Here is the given code to add the new features too: CS401: Lab 12 Advanced GUI D
ID: 3689083 • Letter: H
Question
Here is the given code to add the new features too:
CS401: Lab 12 Advanced GUI Development with JavaF> In this lab, you will add a few features to the "Pizza Order" program (PizzaOrder.java) Compile and run PizzaOrder.java to see what the interface looks like, then test the program on some arbitrary inputs You will need to add the following controls: 1. A "X-Large" radio button 2. A "Green Peppers" check box 3. A "Onions" check box Also, you will add prices to the sizes and to the toppings; specifically, make the prices as follows for the sizes: o all $8 Medium $10 $12 ·X-Large $14 Large Set the price of each topping to be $1. The final feature you need to add is a calculation of the total cost in the "Order Details" dialog box Below is an example screenshot of the new interface and modified dialog box.Explanation / Answer
import java.awt.*;
import java.applet.*;
import javax.swing.*;
public class Pizzaform extends JApplet {
Container contentPane = getContentPane();
public void init() {
/Firstly we will create a panel object and after that we will set its layout manager to put the components in a column
JPanel myPanel = new JPanel();
myPanel.setLayout(new GridLayout(20, 1, 10, 10));
myPanel.setBackground(Color.blue);
// now let us create a label for the form heading and add it to the panel
Label myLabel = new Label("ORDER YOUR PIZZA NOW");
myPanel.add(myLabel);
// we will now create text fields for the customer's name , address and phonenumber and add them to the panel
JLabel nameLabel = new JLabel("Name:");
JTextField myName = new JTextField(30);
JLabel addressLabel = new JLabel("Address:");
JTextField myAddress = new JTextField(30);
JLabel phoneLabel= new JLabel("Phone Number");
JTextField myPhone = new JTextField(30);
myPanel.add(nameLabel);
myPanel.add(myName);
myPanel.add(addressLabel);
myPanel.add(myAddress);
myPanel.add(phoneLabel);
myPanel.add(myPhone);
// Now let is create the radio buttons for pizza size and add them to the panel
JLabel sizeLabel = new JLabel("Pizza Size");
ButtonGroup sizeGrouphere = new ButtonGroup();
JRadioButton p1 = new JRadioButton("small");
JRadioButton p2 = new JRadioButton("medium");
JRadioButton p3 = new JRadioButton("large", true);
JRadioButton p4= new JRadioButton("x-large", true);
// Next we will put the radio buttons in the button group
sizeGrouphere.add(p1);
sizeGrouphere.add(p2);
sizeGrouphere.add(p3);
// Now we will put the radio buttons in the panel
myPanel.add(sizeLabel);
myPanel.add(p1);
myPanel.add(p2);
myPanel.add(p3);
// This is done to create checkboxes for toppings and adding them to the panel
JLabel topLabel = new JLabel("Toppings");
Checkbox z1 = new Checkbox("sausage");
Checkbox z2 = new Checkbox("pepperoni");
Checkbox z3 = new Checkbox("onions");
Checkbox z4 = new Checkbox("tomatoes");
Checkbox z5 = new Checkbox("olives");
Checkbox z6 = new Checkbox("mushrooms");
Checkbox z7 = new Checkbox("green peppers");
myPanel.add(topLabel);
myPanel.add(z1);
myPanel.add(z2);
myPanel.add(z3);
myPanel.add(z4);
myPanel.add(z5);
myPanel.add(z6);
myPanel.add(z7);
// Finally we will perform the adding the panel to the content pane
contentPane.add(myPanel);
}
}