Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

this code is not printing the right info the picture should look like this import java.awt.* ; import javax.swing.* ; import java.awt.event.* ; class Pizzeria

this code is not printing the right info the picture should look like this image text in transcribed

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) ; } }

Pizza Order Formm HVCC Pizza Parlor Choose your pizza size and toppings ($1 each) Eggplant Green Peppers 151 Hot Peppers Pepperoni Sausage Mushrooms Anchovies Small ($7) Medium ($9) Large ($11) X-Large ($13) Price of your pizza is S18.00 Side Order Hot Wings-add $5.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions