import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Menu extends JFrame {
private JTextField partyNumField, dinerName;
private JComboBox orderComboBox;
private int partyNum;
private JButton getParty, continueOrder;
private JLabel party, companyLogo, dinerLabel, entreeOrder;
private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"};
private JCheckBox mashed, cole, baked, french;
public Menu() {
super("O'Brien Caterer - Where we make good Eats!"
Container container = getContentPane();
JPanel northPanel = new JPanel();
northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 80, 5));
companyLogo = new JLabel("Welcome to O'Brien's Caterer's"
northPanel.add(companyLogo);
party = new JLabel("Enter the Total Number in Party Please"
partyNumField = new JTextField(5);
northPanel.add(party);
northPanel.add(partyNumField);
getParty = new JButton("GO - Continue with Order"
getParty.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent actionEvent)
{
partyNum = Integer.parseInt(partyNumField.getText());
String ans=JOptionPane.showInputDialog(null, "Total Number is party is: "
+ partyNum + " is this correct?\n\n" + "Enter 1 to continue\n"
+ "Enter 2 to cancel\n"
if (ans.equals("1") {
System.out.println(ans+"=continue" // handle continue
} else { // assume to be 2 for cancel
System.out.println(ans+"=cancel" // handle cancel
}
}
}
); // end Listener
northPanel.add(getParty);
JPanel middlePanel = new JPanel();
middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
dinerLabel = new JLabel("Please enter Diner's name"
dinerName = new JTextField(30);
continueOrder = new JButton("continue"
middlePanel.add(dinerLabel);
middlePanel.add(continueOrder);
middlePanel.add(dinerName);
entreeOrder = new JLabel("Please choose an entree"
orderComboBox = new JComboBox(dinnerEntree);
orderComboBox.setMaximumRowCount(4);
//orderComboBox.addItemListener(
// new ItemListener(){
// public void itemsStateChanged(ItemEvent event)
// {
// if (event.getStateChange() == ItemEvent.SELECTED)
// add entree order to Person
// continue ** enable the two sides order
// }
// }
// );
mashed = new JCheckBox("Mashed Potatoes"
middlePanel.add(mashed);
cole = new JCheckBox("Cole Slaw"
middlePanel.add(cole);
baked = new JCheckBox("Baked Beans"
middlePanel.add(baked);
french = new JCheckBox("FrenchFries"
middlePanel.add(french);
// CheckBoxHandler handler = new CheckBoxHandler();
// mashed.addItemListener(handler);
// cole.addItemListener(handler);
// baked.addItemListener(handler);
// french.addItemListener(handler);
middlePanel.add(entreeOrder);
middlePanel.add(orderComboBox);
container.add(northPanel);
container.add(middlePanel);
middlePanel.setEnabled(true);
setSize(500, 500);
show();
}
// private class to handle event of choosing Check BOx Item
// private class CheckBoxHandler implements ItemListener{
// private int count = 0;
// public void itemStateChanged(ItemEvent event){
// if (event.getsource() == mashed)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
// add mashed choice to person's order
// if (event.getsource() == cole)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add cole slaw to person's order
// if (event.getsource() == baked)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add baked beans to person's order
// if (event.getsource() == french)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add french to person's order
// }
public static void main(String args[])
{
Menu application = new Menu();
application.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent windowEvent)
{
System.exit(0);
}
}
);
}
}
import java.awt.event.*;
import javax.swing.*;
public class Menu extends JFrame {
private JTextField partyNumField, dinerName;
private JComboBox orderComboBox;
private int partyNum;
private JButton getParty, continueOrder;
private JLabel party, companyLogo, dinerLabel, entreeOrder;
private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"};
private JCheckBox mashed, cole, baked, french;
public Menu() {
super("O'Brien Caterer - Where we make good Eats!"
Container container = getContentPane();
JPanel northPanel = new JPanel();
northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 80, 5));
companyLogo = new JLabel("Welcome to O'Brien's Caterer's"
northPanel.add(companyLogo);
party = new JLabel("Enter the Total Number in Party Please"
partyNumField = new JTextField(5);
northPanel.add(party);
northPanel.add(partyNumField);
getParty = new JButton("GO - Continue with Order"
getParty.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent actionEvent)
{
partyNum = Integer.parseInt(partyNumField.getText());
String ans=JOptionPane.showInputDialog(null, "Total Number is party is: "
+ partyNum + " is this correct?\n\n" + "Enter 1 to continue\n"
+ "Enter 2 to cancel\n"
if (ans.equals("1") {
System.out.println(ans+"=continue" // handle continue
} else { // assume to be 2 for cancel
System.out.println(ans+"=cancel" // handle cancel
}
}
}
); // end Listener
northPanel.add(getParty);
JPanel middlePanel = new JPanel();
middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
dinerLabel = new JLabel("Please enter Diner's name"
dinerName = new JTextField(30);
continueOrder = new JButton("continue"
middlePanel.add(dinerLabel);
middlePanel.add(continueOrder);
middlePanel.add(dinerName);
entreeOrder = new JLabel("Please choose an entree"
orderComboBox = new JComboBox(dinnerEntree);
orderComboBox.setMaximumRowCount(4);
//orderComboBox.addItemListener(
// new ItemListener(){
// public void itemsStateChanged(ItemEvent event)
// {
// if (event.getStateChange() == ItemEvent.SELECTED)
// add entree order to Person
// continue ** enable the two sides order
// }
// }
// );
mashed = new JCheckBox("Mashed Potatoes"
middlePanel.add(mashed);
cole = new JCheckBox("Cole Slaw"
middlePanel.add(cole);
baked = new JCheckBox("Baked Beans"
middlePanel.add(baked);
french = new JCheckBox("FrenchFries"
middlePanel.add(french);
// CheckBoxHandler handler = new CheckBoxHandler();
// mashed.addItemListener(handler);
// cole.addItemListener(handler);
// baked.addItemListener(handler);
// french.addItemListener(handler);
middlePanel.add(entreeOrder);
middlePanel.add(orderComboBox);
container.add(northPanel);
container.add(middlePanel);
middlePanel.setEnabled(true);
setSize(500, 500);
show();
}
// private class to handle event of choosing Check BOx Item
// private class CheckBoxHandler implements ItemListener{
// private int count = 0;
// public void itemStateChanged(ItemEvent event){
// if (event.getsource() == mashed)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
// add mashed choice to person's order
// if (event.getsource() == cole)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add cole slaw to person's order
// if (event.getsource() == baked)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add baked beans to person's order
// if (event.getsource() == french)
// if (event.getStateChange() == ItemEvent.SELECTED)
// count++;
//add french to person's order
// }
public static void main(String args[])
{
Menu application = new Menu();
application.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent windowEvent)
{
System.exit(0);
}
}
);
}
}