Question
Assignment due in 4 hours, what is wrong with my code? Supposed to write a program that allows a user to selected their desired pizza
Assignment due in 4 hours, what is wrong with my code? Supposed to write a program that allows a user to selected their desired pizza and the total will be produced. I have errors more towards the adding all of my check boxes and labels to my panel. Please explain what I am doing wrong. Thank you! The addItemListener and below are potentially incorrect.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class pizza extends JFrame implements ActionListener {
JRadioButton rb1, rb2, rb3;
Checkbox cb1, cb2, cb3;
JButton button;
JTextField text1;
double cost = 0;
Label label = new Label();
pizza(){
JFrame frame = new JFrame();
label.setAlignment(Label.LEFT);
label.setSize(400, 100);
label.setText("Joe's Pizza");
label.setBounds(0, 5, 100, 30);
text1 = new JTextField();
text1.setBounds(500, 5, 150, 200);
rb1 = new JRadioButton("Cheese");
rb1.setBounds(100, 50, 100, 30);
rb2 = new JRadioButton("Pepperoni");
rb2.setBounds(100, 100, 100, 30);
rb3 = new JRadioButton("Veggie");
rb3.setBounds(100, 150, 100, 30);
ButtonGroup bougie = new ButtonGroup();
bougie.add(rb1);
bougie.add(rb2);
bougie.add(rb3);
button = new JButton("Calculate Total: ");
button.setBounds(0, 250, 600, 30);
button.addActionListener(this);
cb1 = new Checkbox("Extra Cheese");
cb1.setBounds(200, 50, 100, 30);
cb2 = new Checkbox("Bacon");
cb2.setBounds(200, 100, 100, 30);
cb3 = new Checkbox("Mushroom");
cb3.setBounds(200, 150, 100, 30);
add(cb1);
add(cb2);
add(cb3);
add(label);
add(rb1);
add(rb2);
add(rb3);
add(button);
add(text1);
cb1.addItemListener(new ItemListener());
public void itemStateChanged1(ItemEvent e) {
cost = cost + 1.5;
}
cb2.addItemListener(new ItemListener()) {
public void itemStateChanged(ItemEvent e) {
cost = cost + 1.5;
}
cb3.addItemListener(new ItemListener()) {
public void itemStateChanged(ItemEvent e) {
cost = cost + 1.5;
}
void setSize(600, 350);
setLayout(null);
setVisible(true);
}
public static void main(String args[]) {
new pizza();
}
}
public void actionPerformed(ActionEvent e) {
if(rb1.isSelected()) {
cost = cost + 10;
text1.setText(cost + "");
cost = 0;
}
if(rb3.isSelected()) {
cost = cost + 15;
text1.setText(cost + "");
cost = 0;
}
}
Assignment due in 4 hours, what is wrong with my code? Supposed to write a program that allows a user to selected their desired pizza and the total will be produced. I have errors more towards the adding all of my check boxes and labels to my panel. Please explain what I am doing wrong. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started