Question
Given the following code, which is attached as an image below , can someone help me with adding another user-defined exception that catches when the
Given the following code, which is attached as an image below, can someone help me with adding another user-defined exception that catches when the user inputs a value greater than 100, a pop-up window displays with a message stating that they must call the restaurant for large orders?
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class WK7PhillipsA {
public static class PizzaMenu extends JFrame {
private JFrame mainFrame;
private JLabel frameTitle;
private JPanel framePanel;
// JButton
private static JRadioButton smallButton, medButton, largeButton;
ButtonGroup sizeGroup;
public PizzaMenu(String frameTitle) {
this.mainFrame = new JFrame(frameTitle);
this.frameTitle = new JLabel(frameTitle);
this.framePanel = new JPanel();
this.smallButton = new JRadioButton("Small");
this.medButton = new JRadioButton("Medium");
this.largeButton = new JRadioButton("Large");
this.sizeGroup = new ButtonGroup();
sizeGroup.add(smallButton);
sizeGroup.add(medButton);
sizeGroup.add(largeButton);
}
// JFrame
private void formatFrame() {
this.mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.mainFrame.setBounds(100, 200, 300, 300);
framePanel.add(frameTitle);
smallButton.setBounds(75,50,100,30);
medButton.setBounds(300,80,100,30);
largeButton.setBounds(75,160,100,30);
framePanel.add(smallButton);
smallButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ie) {
getQuanitiy("Small");
}
});
framePanel.add(medButton);
medButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ie) {
getQuanitiy("Medium");
}
});
framePanel.add(largeButton);
largeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ie) {
getQuanitiy("Large");
}
});
mainFrame.add(framePanel);
mainFrame.setVisible(true);
}
private void getQuanitiy(String pizzaSize) {
try {
JFrame inputDialog;
inputDialog = new JFrame();
String numberInput = JOptionPane.showInputDialog(inputDialog, "How many " + pizzaSize +" pizzas " + " would you like?");
int userInput = Integer.parseInt(numberInput);
JOptionPane.showMessageDialog(null, "You want to order "+ userInput + " " + pizzaSize + " pizzas.", "Pizzas ordered", JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e) {
JOptionPane.showMessageDialog(null,"ERROR INVALID INPUT","ERROR",JOptionPane.ERROR_MESSAGE);
}
}
public boolean buttonsPressed() {
return false;
}
public void runMenu() {
this.formatFrame();
}
}
public static void main(String[] args) {
String frameTitle = "Pizza Size Choices";
PizzaMenu sizeMenu = new PizzaMenu(frameTitle);
sizeMenu.runMenu();
}
}
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