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

I just need to know how to make the JButton active. I\'ve asked for homework hel

ID: 3647393 • Letter: I

Question

I just need to know how to make the JButton active.

I've asked for homework help a couple of times, and still can't resolve HOW to make the buttons active. I just don't know what to do next. The java structure is what is required, but I don't know how to make it total up the amount of pizzas, and make the buttons active. You can see that I have done the work, I am just stuck. Please, someone just show me the whole functioning code if you can. Thank you so much! This is due in 2 days and I can't figure it out.

Pizza class that extends JFrame
two radio buttons, in a group, with Crust title and border (thick, thin)
three check boxes, with Topppings title and border (pepperoni, mushroom, olives)
two JButtons (Order, Cancel)
main panel
grouped buttons instantiated and linked to panel
instantiate and add the JButtons to main panel
set visible frame

In the frame code an inner class event listener that implements the interface ActionListener when user clicks any buttons. Instantiate an object of this inner and register it to both JButtons.

When Order button pushed, it checks to make sure a Crust was chosen.
{
If thick or thin was pushed, use JOptionPane to display which crust was chosen and any/all/none topppings checkboxes chosen (all these options need to be messaged). It accepts the Order and clears all buttons of activity.

If a crust radio button was NOT pushed, use JOptionPane to say "try again". It does not accept the choice and clears all buttons of activity, ready for the next attempt.
}


When JButton Cancel is pushed, the JOptionPane displays total pizzas sold for the day, and Thick <number sold>, Thin <number sold>

Then is says "Enjoy your pizza" and ends.

The test application needs to be create an object of the frame (Pizza Store) and display it. The inner class should work independently of the test application.

graded on:
*ONLY ONE crust can be chosen at a time
*more than one toppping can be chosen
*when Order is pushed the JOptionPane throws error message if no crust chosen
*system cleans all boxes
*system gives order summary with JOptionPane and accepts pizza order if one crust was chosen
*system cleans all boxes
*when Cancel is pushed the JOptionPane gives order summary and then ends application


So far I have:


public class PizzaStore extends JFrame {
private JPanel p1, cPanel, tPanel;
private JButton order, cancel;
private JCheckBox t1, t2, t3;
private JRadioButton c1, c2;


public PizzaStore(){
this.setTitle("Pizza Store");
p1 = new JPanel();
this.setSize(500, 500);
this.setVisible(true);
this.add(p1);

cPanel = new JPanel();
setCrust(50, 100);
Border b1 = BorderFactory.createTitledBorder("Crust");
cPanel.setBorder(b1);
c1 = new JRadioButton("Thin Crust");
cPanel.add(c1);
c2 = new JRadioButton("Thick Crust");
cPanel.add(c2);
p1.add(cPanel);

tPanel = new JPanel();
setToppping(50, 150);
Border b2 = BorderFactory.createTitledBorder("Topppings");
tPanel.setBorder(b2);
t1 = new JCheckBox("Pepperonis");
tPanel.add(t1);
t2 = new JCheckBox("Mushrooms");
tPanel.add(t2);
t3 = new JCheckBox("Olives");
tPanel.add(t3);
p1.add(tPanel);

order = new JButton();
order.setText("Order Pizza");
order.addActionListener(this);
p1.add(order);
cancel = new JButton();
cancel.setText("Cancel Order");
cancel.addActionListener(this);
p1.add(cancel); }

private class EventListener implements ActionListener { public void actionPerformed(ActionEvent event){ boolean addPepperonis = false;
boolean addMushrooms = false;
boolean addOlives = false;
String message = "Crust";

if (event.getSource() == order) {
if(t1.isSelected()) addPepperonis = true;
event.getActionCommand();
if(t2.isSelected()) addMushrooms = true;
event.getActionCommand();

if(t3.isSelected()) addOlives = true;
event.getActionCommand(); }
else if(event.getSource() == cancel) {
System.exit(0);}

if(c1.isSelected()) {
message = " Thick " topppings;
event.getActionCommand(); }
if(c2.isSelected()) {
message = " Thin " topppings; event.getActionCommand(); }
t1.setSelected(false);
t2.setSelected(false);
t3.setSelected(false); }
}
}

Explanation / Answer

//I have removed many of the errors // i'm little bit confused about your buttons import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; import javax.swing.border.Border; public class PizzaStore extends JFrame { private JPanel p1, cPanel, tPanel; private JButton order, cancel; private JCheckBox t1, t2, t3; private JRadioButton c1, c2; public PizzaStore(){ this.setTitle("Pizza Store"); p1 = new JPanel(); this.setSize(500, 500); this.setVisible(true); this.add(p1); cPanel = new JPanel(); //setCrust(50, 100); Border b1 = BorderFactory.createTitledBorder("Crust"); cPanel.setBorder(b1); c1 = new JRadioButton("Thin Crust"); cPanel.add(c1); c2 = new JRadioButton("Thick Crust"); cPanel.add(c2); p1.add(cPanel); tPanel = new JPanel(); //setToppping(50, 150); Border b2 = BorderFactory.createTitledBorder("Topppings"); tPanel.setBorder(b2); t1 = new JCheckBox("Pepperonis"); tPanel.add(t1); t2 = new JCheckBox("Mushrooms"); tPanel.add(t2); t3 = new JCheckBox("Olives"); tPanel.add(t3); p1.add(tPanel); order = new JButton(); order.setText("Order Pizza"); //order.addActionListener(this); p1.add(order); cancel = new JButton(); cancel.setText("Cancel Order"); //cancel.addActionListener(this); p1.add(cancel); } private void setCrust(int i, int i0) { throw new UnsupportedOperationException("Not yet implemented"); } private void setToppping(int i, int i0) { throw new UnsupportedOperationException("Not yet implemented"); } private class EventListener implements ActionListener { private String topppings; public void orderactionPerformed(ActionEvent event){ boolean addPepperonis = false; boolean addMushrooms = false; boolean addOlives = false; String message;// = "Crust"; if (event.getSource() == order) { if(t1.isSelected()) addPepperonis = true; event.getActionCommand(); if(t2.isSelected()) addMushrooms = true; event.getActionCommand(); if(t3.isSelected()) addOlives = true; event.getActionCommand(); } else if(event.getSource() == cancel) { System.exit(0);} if(c1.isSelected()) { message = " Thick " + topppings ; event.getActionCommand(); } if(c2.isSelected()) { message = " Thin "+ topppings; event.getActionCommand(); } t1.setSelected(false); t2.setSelected(false); t3.setSelected(false); } public void cancelActionPerformed(java.awt.event.ActionEvent evt){ System.exit(0); } @Override public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); } } public static void main(String args[]) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(PizzaStore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PizzaStore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(PizzaStore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PizzaStore.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new PizzaStore().setVisible(true); } }); } }