Create a GUI for ordering a pizza. Use a JFrame as the main window. On the main
ID: 3877055 • Letter: C
Question
Create a GUI for ordering a pizza.
Use a JFrame as the main window. On the main window include buttons for login, order pizza, find coupon, offer feedback. Put a picture of pizza on the main page in a JLabel. Include a textarea at the bottom to show the pizza that the customer will be ordering.
Make the order pizza button open a JDialog (add -> Java swing gui -> JDialog). Include the following options: Crust Size (radio buttons) 8” , 10”, ”
Crust Type (radio buttons) thin crust, deep dish
Toppings (check boxes) extra cheese, pepperoni, At the bottom of the ordering dialog, you should have a button that checks to ensure customers have selected Size and Type of pizza. Toppings are optional. The form should be setVisible(false) after checking validity. You will also have to write a return method in the dialog class that your JFrame can call to retrieve the values.
Once the main class retrieves the values, put them in the textarea at the bottom of the form. The remaining buttons on the main form are just dummies. We may
Main Form - 25 create buttons: 5 create dialog: 5 picture: 5 display values: 5 style: 5 Dialog - 25 radio buttons: 5 check boxes: 5 testing: 5 return method: 5 style: 5
Explanation / Answer
import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JSlider; import javax.swing.JTextField; /** * Creates a form that allows someone to order a pizza. * This version displays Swing components that are organized * reasonably but does not do anything with the * user input. * * @author Barbara Lerner * @version February 3, 2010 * */ public class PizzaOrder { /** * Creates the panel that holds the buttons to place or cancel the order * @return the button panel */ private JPanel createButtonPanel() { JPanel buttonPanel = new JPanel(); buttonPanel.add (new JButton("Place order")); buttonPanel.add (new JButton("Cancel order")); return buttonPanel; } /** * Creates the panel with the temperature slider * @return the temperature panel */ private JPanel createTemperaturePanel() { JPanel temperaturePanel = new JPanel(); temperaturePanel.add (new JLabel ("Temperature")); temperaturePanel.add (new JSlider()); return temperaturePanel; } /** * Creates the menu of toppings * @return the menu of toppings */ private JComboBox createToppingsMenu() { JComboBox comboBox = new JComboBox(); comboBox.addItem("Pepperoni"); comboBox.addItem("Mushrooms"); comboBox.addItem("Anchovies"); return comboBox; } /** * Creates the panel where the name of the person placing the order is entered. * @return the name panel */ private JPanel createNamePanel() { JPanel namePanel = new JPanel(); namePanel.add (new JLabel("Name: ")); namePanel.add (new JTextField(15)); return namePanel; } /** * Creates the panel to select delivery * @return the delivery panel */ private JPanel createDeliveryPanel() { JPanel deliveryPanel = new JPanel(); deliveryPanel.add (new JCheckBox()); deliveryPanel.add (new JLabel("Delivery")); return deliveryPanel; } /** * A program to display a pizza order form. * @param args None expected. */ public static void main(String[] args) { JFrame f = new JFrame(); f.setTitle("Pizza Order"); // Create the panel that will display the image and text PizzaOrder order = new PizzaOrder(); Container contentPane = f.getContentPane(); // Delivery JPanel deliveryPanel = order.createDeliveryPanel(); contentPane.add (deliveryPanel, BorderLayout.NORTH); // Person ordering JPanel namePanel = order.createNamePanel(); contentPane.add(namePanel, BorderLayout.SOUTH); // Toppings JComboBox comboBox = order.createToppingsMenu(); contentPane.add(comboBox, BorderLayout.CENTER); // Temperature JPanel temperaturePanel = order.createTemperaturePanel(); contentPane.add(temperaturePanel, BorderLayout.WEST); // Order and cancel buttons JPanel buttonPanel = order.createButtonPanel(); contentPane.add(buttonPanel, BorderLayout.EAST); // Make the window the minimum size that displays all // components. f.pack(); // Display the window. f.setVisible(true); } }