Pizza Delivery Order Form Applet
The Order Form applet is used at the counter for taking pizza delivery orders. Customers usually call up the pizza shop and order the pizza over the phone. This design is meant for helping the person taking the orders. Thus the first section of the GUI deals with the details of the person calling in, like the phone number, address, etc,. Then the different varities of pizzas are listed from which customers can choose either a ready made pizza or a custom made pizza. Finally the two buttons at the bottom prints the order or cancels the order.
The check boxes for selecting the pizza and the list boxes for choosing the ingredients for the pizza work together. For eg., if the customer chooses a veggie pizza by selecting the corresponding checkbox, then a list of all the vegetables present in this pizza are displayed in the final ingredients list on the right. From this list components can be removed or added using the right and left arrow buttons. If the make your own pizza is selected, a list of available ingredients are listed on the left from which the required components can be selected and put into the list on the right using the right arrow key.
- Source Code : BannerPage.java, IngredientList.java, OrderForm.java, PizzaApplet.java
- Applet Demo
Design Notes
The applet uses four main classes for building the GUI. The main applet class is the PizzaApplet class which uses BorderLayout scheme to put a BannerPage component on top of the page and an OrderForm component below it. The BannerPage class is extended from Canvas and it just displays the banner on top. The OrderForm component is the main class which has all the other components that adds functionalities to the applet. It uses the GridBagLayout and GribBagConstraints classes for placing the components on the screen appropriately. Several components like Textfields, Buttons, Checkboxes are placed appropriately on the Panel. It uses the addComp method in the OrderForm class to actually place the components and uses the Insets class to give appropriate distances from the borders of the components.
Two custom components that are placed on the Panel are the lists built using the IngredientList class which itself extends from the List class. It has two constructors, one which builds an empty list and another one which takes in an array of elements and builds the list. There are other methods to add elements in a sorted order to the list etc. There are two list components placed on the Panel, one for the initial Ingredients and another one listing the final Ingredients in the list. The two buttons with right and left arrows are used for putting the components back and forth between these two lists. Initially when no pizzas are selected then these buttons are inactive.
Apart from placing these components, the OrderForm class implements three Listener Interfaces, namely the ActionListener for trapping the events generated by the buttons, the TextListener for trapping the events generated by the Textfields and the ItemListener for trapping events from the checkbox selections. The various methods implemented for these interfaces use the getSource method to determine the actual origin of the event to decide on which button or check box was actually clicked.
There are other methods defined in the OrderForm class for clearing the filed and displaying the default values, for displaying the output of the print button.(Note this uses a simple drawString and prints the output on the applet screen itself. A better display of output could be added instead.) Several error checking methods are also present in this class to check if values greater than what the Textfields could accept are given. Error messages are again displyed at the bottom of the applet in the same way as the output. Error messages are also displayed if certain fields are left empty. Only the City field is optional. All the other fields are necessary. The pay by field has a default value of Cash. If any of the other fields are not selected, then an error message will be printed upon clicking the Print button. Cancel button clears all the textfields and displays the default values for the check boxes and the list elements.