Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a frame with components for an order form for a pizza. The frame should be

ID: 3687182 • Letter: W

Question

Write a frame with components for an order form for a pizza. The frame should be able to run itself and include an appropriate title bar. All your frame components will have an appropriate pizza colored background and foreground. The purpose of this exercise is to show layouts and panels with different kinds of events. You will use a border layout with panels to divide the frame into 3 sections - top, middle, and bottom. All of the sections will use the panels with a grid layout for the multiple components.

The top section will have the centered title telling the name of the company (in a larger and different style typeface) and underneath it separate centered instructions to choose your pizza size and toppings.

The middle section will have four radio buttons in a button group: small - $7, medium - $9, large - $11, and extra large - $13. The right side of the middle section will also have a list object for the available toppings - Eggplant, Green Peppers, Hot Peppers, Pepperoni, Sausage, Mushrooms, and Anchovies (of which they can pick as many as they want from 0 - 7). Each topping will add $1 to the total price. Before they pick any pizza size or toppings, there should be no size or toppings selected.

The bottom section will have first a label saying "Price of your pizza is $0.00", and then to the right of the price label will be a checkbox promoting a $5.00 side order of hot wings. The price of the pizza will be updated as they pick different sizes or toppings, also in a larger point size and different typeface with the price formatted in Currency.

Use the setSize() for the frame, but be careful of the sizing, components tend to fill up unused areas in a border layout. For the list, make sure you can see all items but don't let there be any extra space, just resize the frame so everything fits and there is no extra space and don=t let the user change the frame=s size on you.

As soon as the user clicks on a new size, topping, or the wings check box, update the price immediately. Let the user make changes to the form as often as they want, seeing the updated price immediately. Have a price variable for the size price (which could include the extra wings price), a price variable for the topping price, and a total price. Only calculate and update what they change (ex. if they add a topping, the size does not have to be recalculated).

When they pick a size radio button, check to see which one they picked and change the size price (you will be an ItemListener). Then check to see if the wings check box is checked off, if so then add the $5.00 to the size price. Add to this size price the topping price, format the final price to Currency and update the price label. When they pick a topping or toppings (hold control key down for multiple toppings), calculate the topping price (add $1.00 for each topping they picked) (you will be a ListSelectionListener). Add to this the size price, format the final price to Currency, and update the price label.   

1st Run:

Large Pizza with Eggplant and Hot Peppers, with a side order of wings.

2nd Run:

Medium Pizza with Green Peppers, Pepperoni, and Mushrooms, without a side order of wings.

Explanation / Answer

Hi below i have written a sample code for Pizza Application which will helps you understand to add and perform any action for your reference,

import java.awt.* ;
import javax.swing.* ;
import java.awt.event.* ;

class Pizzeria extends JFrame implements ActionListener, ItemListener
{
private static final int WIDTH = 450 ;
private static final int HEIGHT = 150 ;
private static final int X_ORIGIN = 200 ;
private static final int Y_ORIGIN = 100 ;
  
private static final double smallPizzaPrice = 7.00 ;
private static final double mediumPizzaPrice = 9.00 ;
private static final double largePizzaPrice = 11.00 ;
private static final int smallPizzaSize = 0 ;
private static final int mediumPizzaSize = 1 ;
private static final int largePizzaSize = 2 ;
private static final int TRUE = 1 ;
private static final int FALSE = 0 ;
int states = 0 ;
double totalPrice = 0.0;
double pizzaSizePrice = smallPizzaPrice ;
  
  
//Toppings & Panel
JCheckBox pepperoni ;
JCheckBox cheese ;
JCheckBox sausage ;
JCheckBox peppers ;
JCheckBox olives ;
JPanel checkboxPanel ;
  
//Pizza Size & Panel
JComboBox pizzaSize ;
JPanel comboboxPanel ;
  
//Price Calc. Button & Panel
JButton calculatePrice ;
JPanel buttonPanel ;
  
//Price Display Field and Panel
JTextField message ;
JPanel messagePanel ;
  
public Pizzeria()
{
super("Pizzeria") ;
  
pizzaSize = new JComboBox() ;
pizzaSize.addItem( "Small" ) ;
pizzaSize.addItem( "Medium" ) ;
pizzaSize.addItem( "Large" ) ;
pizzaSize.setSelectedIndex(0) ;
pizzaSize.addItemListener(this) ;
  
pepperoni = new JCheckBox("Pepperoni") ;
pepperoni.addItemListener(this) ;
cheese = new JCheckBox("Cheese") ;
cheese.addItemListener(this) ;
sausage = new JCheckBox("Sausage");
sausage.addItemListener(this) ;
peppers = new JCheckBox("Peppers");
peppers.addItemListener(this) ;
olives = new JCheckBox("Olives");
olives.addItemListener(this) ;

calculatePrice = new JButton( "Calculate Price" ) ;
calculatePrice.addActionListener(this) ;
  
message = new JTextField(10) ;

//setSize( 300, 200 ) ;
  
Container contentPane = getContentPane() ;
GridLayout contentpaneLayout = new GridLayout(4,0,10,10) ;
contentPane.setLayout(contentpaneLayout) ;
  
comboboxPanel = new JPanel() ;
GridLayout comboboxPanelLayout = new GridLayout(1,1) ;
comboboxPanel.setLayout(comboboxPanelLayout) ;
comboboxPanel.add(pizzaSize) ;
contentPane.add(comboboxPanel) ;
  
checkboxPanel = new JPanel() ;
GridLayout checkboxPanelLayout = new GridLayout(1,1) ;
checkboxPanel.setLayout(checkboxPanelLayout) ;
checkboxPanel.add(pepperoni) ;
checkboxPanel.add(cheese) ;
checkboxPanel.add(sausage) ;
checkboxPanel.add(peppers) ;
checkboxPanel.add(olives) ;
contentPane.add(checkboxPanel) ;
  
buttonPanel = new JPanel() ;
GridLayout buttonPanelLayout = new GridLayout(1,1) ;
buttonPanel.setLayout(buttonPanelLayout) ;
buttonPanel.add(calculatePrice) ;
contentPane.add(buttonPanel) ;
  
messagePanel = new JPanel() ;
GridLayout messagePanelLayout = new GridLayout(1,1) ;
messagePanel.setLayout(messagePanelLayout) ;
messagePanel.add(message) ;
contentPane.add(messagePanel) ;
  
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ;
setBounds(X_ORIGIN, Y_ORIGIN, WIDTH, HEIGHT) ;
}
  
public void actionPerformed(ActionEvent e)
{
System.out.println("Enter");
            
Object source = e.getSource() ;
  
//if
//{   
// pizzaSize = (JComboBox)e.getSource() ;
int pizzaSiz = (int)pizzaSize.getSelectedIndex() ;
                         
System.out.println(pizzaSiz);
if (pizzaSiz == smallPizzaSize)
{System.out.println("Enter");
pizzaSizePrice = smallPizzaPrice ;
}
else if (pizzaSiz == mediumPizzaSize)
{
pizzaSizePrice = mediumPizzaPrice ;
}
else if (pizzaSiz == largePizzaSize)
{
pizzaSizePrice = largePizzaPrice ;
}
  
if (source == calculatePrice)
{
totalPrice = pizzaSizePrice ;
totalPrice += states ;
message.setText( "" + totalPrice) ;
}

  

}
      
public void itemStateChanged(ItemEvent e)
{
Object source = e.getSource() ;
  
// if the source of the event was a Toggle Button
  
if (source instanceof JToggleButton)
{
getComponentStates() ;
}
}
  
int getComponentStates()
{
states = 0 ;
if (pepperoni.isSelected())
{
states= states + 1;
}
  
if (cheese.isSelected())
{
states= states + 1;
}
  
if (sausage.isSelected())
{
states= states + 1 ;
}
  
if (peppers.isSelected())
{
states= states + 1 ;
}
if (olives.isSelected())
{
states= states + 1 ;
}
  
return states ;
}
}

public class PizzeriaApp
{
public static void main(String[] args)
{
Pizzeria myFrame = new Pizzeria() ;
myFrame.setVisible(true) ;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote