My program "should" 1. Ask for totally number in party 2. Ask if this partyNumber is correct 3. Get Name 3. Get Entree Order 4. Get Side Order 5. If diner number < number in party 6. Go to Step 3.
I've been working in this for forever and I'm at the point where I'm completely confused with what I'm doing. I need a walk away from it from an hour.
The main thing I can't figure out is I continue get Diners names and there orders and present the output. If I choose only one diner if will produce output but if I choose 2 or more people in Party I don't even get any output and I can't understand why? Also if I do say that there is only one person in the party it will produce input but for some reason it outputs the dinner entree of the Diner 3 times?? No side order gets output in my JOptionPane.
Hoping someone could help me a bit with my problems. I've reached a point where I getting completey lost. Any guidance or suggestions would be greatly appreciated.
The output which is resulting from the code is confusing me the most.
P.S. My GUI is pretty wacked but thats another issue in itself and I'll worry about that later. Thanks again.
public class Menu extends JFrame { private JTextField partyNumField, dinerName; private JComboBox orderComboBox; private int partyNum; private JButton getParty, continueOrder, nextDiner; private JLabel party, companyLogo, dinerLabel, entreeOrder; private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"}; private JCheckBox mashed, cole, baked, french; private String output = ""; private String diners[] = new String[100]; //set maximum Diner amounts allowed to 100
public Menu() { // setting up GUI super("O'Brien Caterer - Where we make good Eats!");
Container container = getContentPane();
JPanel northPanel = new JPanel(); northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 120, 15)); 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")) { continueOrder.setEnabled(true); dinerLabel.setEnabled(true); dinerName.setEnabled(true);
// handle continue } else { // assume to be 2 for cancel System.exit(0); // handle cancel } } } ); // end Listener
JPanel middlePanel = new JPanel(); middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER)); dinerLabel = new JLabel("Please enter Diner's name"); dinerLabel.setEnabled(false); dinerName = new JTextField(30); dinerName.setEnabled(false); continueOrder = new JButton("continue"); continueOrder.setEnabled(false);
entreeOrder = new JLabel("Please choose an entree"); entreeOrder.setEnabled(false); orderComboBox = new JComboBox(dinnerEntree); orderComboBox.setMaximumRowCount(5); orderComboBox.setEnabled(false);
orderComboBox.addItemListener( new ItemListener(){ public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) output += (String)orderComboBox.getSelectedItem(); mashed.setEnabled(true); cole.setEnabled(true); french.setEnabled(true); baked.setEnabled(true); } } );
mashed = new JCheckBox("Mashed Potatoes"); middlePanel.add(mashed); mashed.setEnabled(false); cole = new JCheckBox("Cole Slaw"); middlePanel.add(cole); cole.setEnabled(false); baked = new JCheckBox("Baked Beans"); middlePanel.add(baked); baked.setEnabled(false); french = new JCheckBox("FrenchFries"); middlePanel.add(french); french.setEnabled(false);
CheckBoxHandler handler = new CheckBoxHandler(); mashed.addItemListener(handler); cole.addItemListener(handler); baked.addItemListener(handler); french.addItemListener(handler);
// private class to handle event of choosing CheckBoxItem private class CheckBoxHandler implements ItemListener{ private int counter = 0; // counter to enable nextDiner Button when // two choices are selected to enable button
public void itemStateChanged(ItemEvent event){
if (event.getSource() == mashed) if (event.getStateChange() == ItemEvent.SELECTED) output+= (String)orderComboBox.getSelectedItem(); counter++;
if (event.getSource() == cole) if (event.getStateChange() == ItemEvent.SELECTED) output+= (String)orderComboBox.getSelectedItem(); counter++; if (event.getSource() == baked) if (event.getStateChange() == ItemEvent.SELECTED) output+= (String)orderComboBox.getSelectedItem(); counter++;
if (event.getSource() == french) if (event.getStateChange() == ItemEvent.SELECTED) output+= (String)orderComboBox.getSelectedItem(); counter++;
if (counter >= 2) { nextDiner.setEnabled(true);
} } }
public void displayResults() { JTextArea outputArea = new JTextArea(); outputArea.setText(output); JOptionPane.showMessageDialog(null, output, "Final Order of Party", JOptionPane.INFORMATION_MESSAGE); System.exit(0); }
public static void main(String args[]) { Menu application = new Menu(); application.addWindowListener( new WindowAdapter(){ public void windowClosing(WindowEvent windowEvent) { System.exit(0); } } ); } } package finalproject;
public class Menu extends JFrame { private JTextField partyNumField, dinerName; private JComboBox orderComboBox; private int partyNum; private JButton getParty, continueOrder, nextDiner; private JLabel party, companyLogo, dinerLabel, entreeOrder; private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"}; private JCheckBox mashed, cole, baked, french; private String output = ""; private String diners[] = new String[100]; //set maximum Diner amounts allowed to 100
public Menu() { // setting up GUI super("O'Brien Caterer - Where we make good Eats!");
Container container = getContentPane();
JPanel northPanel = new JPanel(); northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 120, 15)); 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")) { continueOrder.setEnabled(true); dinerLabel.setEnabled(true); dinerName.setEnabled(true);
// handle continue } else { // assume to be 2 for cancel System.exit(0); // handle cancel } } } ); // end Listener
JPanel middlePanel = new JPanel(); middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER)); dinerLabel = new JLabel("Please enter Diner's name"); dinerLabel.setEnabled(false); dinerName = new JTextField(30); dinerName.setEnabled(false); continueOrder = new JButton("continue"); continueOrder.setEnabled(false);
entreeOrder = new JLabel("Please choose an entree"); entreeOrder.setEnabled(false); orderComboBox = new JComboBox(dinnerEntree); orderComboBox.setMaximumRowCount(5); orderComboBox.setEnabled(false);
orderComboBox.addItemListener( new ItemListener(){ public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) output += (String)orderComboBox.getSelectedItem(); mashed.setEnabled(true); cole.setEnabled(true); french.setEnabled(true); baked.setEnabled(true); } } );
mashed = new JCheckBox("Mashed Potatoes"); middlePanel.add(mashed); mashed.setEnabled(false); cole = new JCheckBox("Cole Slaw"); middlePanel.add(cole); cole.setEnabled(false); baked = new JCheckBox("Baked Beans"); middlePanel.add(baked); baked.setEnabled(false); french = new JCheckBox("FrenchFries"); middlePanel.add(french); french.setEnabled(false);
CheckBoxHandler handler = new CheckBoxHandler(); mashed.addItemListener(handler); cole.addItemListener(handler); baked.addItemListener(handler); french.addItemListener(handler);
// private class to handle event of choosing CheckBoxItem private class CheckBoxHandler implements ItemListener{ private int counter = 0; // counter to enable nextDiner Button when // two choices are selected to enable button
public void itemStateChanged(ItemEvent event){
if (event.getSource() == mashed) if (event.getStateChange() == ItemEvent.SELECTED) output+= (String)orderComboBox.getSelectedItem(); counter++;
if (event.getSource() == cole) if (event.getStateChange() == ItemEvent.SELECTED) output+= (String)orderComboBox.getSelectedItem(); counter++; if (event.getSource() == baked) if (event.getStateChange() == ItemEvent.SELECTED) output+= (String)orderComboBox.getSelectedItem(); counter++;
if (event.getSource() == french) if (event.getStateChange() == ItemEvent.SELECTED) output+= (String)orderComboBox.getSelectedItem(); counter++;
Looks like you have two different class definitions for Menu. Maybe you can repost just the one you are using? Also, if you use the java tags (see Formatting Your Post at the bottom of the page, when you are submitting your post), the code will be a lot easier for people to read.