hi everybody
I am currently creating a simulation of a pizza ordering system in object oriented program. I have some question. the instruction and guideline is long but I will try and cut it down a lot. the instruction is to create a program that simulate a pizza restaurant using a GUI it has two bakers and one cashier. both bakers has thier own speciality, if one is absent, the other has to fill in and vice versa according to the orders entered. it also I have to read and process a data file, called pizz_mani_orders.txt to the simulate the operation of the pizza restaurant. also need to compute the salary for each member of staff.
my question is. how do i give the checkboxes, radiobutton and button the functionality it need. this is the codes that i have so far. I am not finish as yet but was wondering if i am going in the right direction. how do i add a checkboxes and radiobuttons and button to a panel
how am I doing so far, am I wrong, right, or in the wrong or right direction. would love you all input.
many thanks in advance
I know that i am not perfect.

package PizzaMania;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.*;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.event.*;

public class PizzaMania extends javax.swing.JFrame {

   private JMenuBar menuBar;
   private JMenu File;
   private JMenuItem Reset;
   private JMenuItem Exit;

   private JCheckBox tomato;
   private JCheckBox greenpepper;
   private JCheckBox blackolives;
   private JCheckBox mushrooms;
   private JCheckBox extracheese;
   private JCheckBox pepperoni;
   private JCheckBox sausage;

   public PizzaMania(){
        super("PizzaMania");
        sendMenuBar();
        sendUI(this);
    }
    private void sendMenuBar(){
        menuBar = new JMenuBar();
        File = new JMenu(" File ");
        Reset= new JMenuItem(" Reset");
        Exit = new JMenuItem(" exit ");
        setJMenuBar(menuBar);
        menuBar.add(File);

       Exit.addActionListener(new ActionListener(){

           @Override
           public void actionPerformed(ActionEvent e){
               System.exit(0);

           }
       });

        File.add(Reset);//still to be coded
        Reset.addActionListener(new ActionListener(){

            @Override
            public void actionPerformed(ActionEvent e){

             }
        });
        File.add(Exit);

       }

    private void sendUI(PizzaMania app){
        app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        app.setSize(600, 700);
        app.setLayout(null);
        app.setLocationRelativeTo(null);
        app.setVisible(true);

    }

    //pizza topping
    JCheckBox Tomato = new JCheckBox(" Tomato");
    JCheckBox GreenPepper = new JCheckBox(" Green Pepper");
    JCheckBox BlackOlives = new JCheckBox(" Black Olives");
    JCheckBox Mushrooms = new JCheckBox(" Mushrooms");
    JCheckBox ExtraCheese = new JCheckBox(" Extra Cheese");
    JCheckBox Pepperoni= new JCheckBox(" Pepperoni");
    JCheckBox Sausage = new JCheckBox(" Sausage");

    JButton placeorder = new JButton("Place Order");
    JButton printallorders = new JButton("Print All Orders");
    JTextField CashierName = new JTextField(" Suzanne ");
    JTextField BakersName = new JTextField(" Gary ");
    JTextField BakerName = new JTextField(" Bishop ");

    //pizza size options
     JRadioButton Small = new JRadioButton("Samll ");
     JRadioButton Medium = new JRadioButton("Medium");
     JRadioButton Large = new JRadioButton("Large");
     JRadioButton Family = new JRadioButton("Family");
     JRadioButton MembersCard = new JRadioButton("Members Card");

      //pizza crust choices
      JRadioButton ThinCrust = new JRadioButton("Thin Crust");
      JRadioButton MediumCrust = new JRadioButton("Medium Crust");
      JRadioButton CrustLover= new JRadioButton("Crust Lover");

     //get the toppings method
    //return the cost of toppings

      public int  getnumofToppingCost(){

          int  toppingCost =0; 
          for(int i=0; i <=7; i++){

              if(tomato.isSelected()){
                   toppingCost +=1;
              }
              if(greenpepper.isSelected()){
                  toppingCost +=1;
              }
              if(blackolives.isSelected()){
                  toppingCost +=1;
              }
              if(mushrooms.isSelected()){
                  toppingCost +=1;
              }
              if(extracheese.isSelected()){
                  toppingCost +=1;
              }
              if(pepperoni.isSelected()){
                  toppingCost +=1;
              }
              if(sausage.isSelected()){
                  toppingCost +=1;
              }

          }
          return toppingCost;

      } 
      //adding radio button to a panel

      //get size method
      public double getSizeCost(){

          double sizeCost =0;
          boolean size = true;

         return sizeCost;
      }

Recommended Answers

All 11 Replies

Hi D2 - hadn't noticed that it was you! :) JC

Sketching out a GUI is a good way to understand the requirements etc, but it's NOT the place to start actual development.

This is an OO exercise, so start with the objects. Look for the important nouns in the problem description - for example Restaurant, Order, Baker, Cashier, Pizza, SIze, Topping, Crust... (maybe you don't need those exact classes, just see how it works out when you add the members and method signatures).
Then hard code a couple of test cases and get all the logic working.

Then design and code the data file processing, which will incidentally give your logic a pretty good test. Think of this as an alternative "user interface" for your classes - so you have one set of classes that represent everything about the restaurant, and two separate ways to use them, one from file , one from GUI.
...
Then and only then create a GUI that uses the functionality that you jave already created and tested. (You may want to add a few more methods to your classes specifically to support the GUI, but these will become obvious when you start coding the GUI.)

When you do, finally, get round to coding the GUI you will find excellent examples and explanations for working with radio buttons etc in the usual Oracle Java Tutorials

thank you james and nice to hear from u. and one more thing. what do you know about observer pattern in object oriented pattern and yes that pizza restaurant program is a oo program. that is what I am doing now. I have pass obj1 and am now on to obj2.

so it is pace for me this semester

Yes, I do know about Observer pattern. It's how Swing event listeners work. You create a Listener (Listener, Observer - they're the same thing) and when things happen or stuff changes your method gets called with the new info. You have to know about the class that will create the event, but that class doen't need to know about you

does it have any tutorial about observer design pattern on this website, j

Which web site do you mean? Anyway, just Google - there are dozens or even hundreds of them.
From what you have posted so far it's not obvious to me how it relates to your current exercise.

hi there i suggest you browse online you definitely will find a webpage with a tuturial on how it works or on how to go about it am definitely sure.

thank you Frank_17 and james and james it does pertain to the program that i posted, apparently I have to use a diagram like that in order to do the program, that is what the lecturer is looking for

If that's what your lecturer wants, then yes, you have to supply it!
Having said that, apart from the user interface itself I can't see where Observer pattern is relevant. The whole of GUI event handling is classic Observer, but that comes as part of AWT/Swing - you don't have to develop it yourself.
Maybe there are other parts of the spec that we haven't seen, in which Observer is applicable?

More thoughts on Observer...

If all you are doing is creating Pizzas then the GUI can call methods to set the size, ingredients etc, then call another method to get the cost or whatever. No need for Observer.
But if you want to include cooking and serving the Pizza then Observer would kick in, ie

The Pizza has states (ordered, being cooked, cooked ready to serve, being served, served, paid for) that change over time. You want those to be visible in the GUI. You could have the Pizza class call a method in the GUI when its state changes, but that means the Pizza class won't work without that specific GUI (eg if you are running from a test data file).

So you make Pizza Observable , which means something like:
Define a PizzaListener interface with a method likevoid pizzaStateChanged(newState).
Implement PizzaListener in your GUI,
Give Pizza an addListener(PizzaListener) method
GUI uses that method to add itself as a listener to each Pizza as its created.
Every time the pizza's state changes, call each listener's pizzaStateChanged
Now when the pizza's state changes the GUI method is called and the GUI can update its display. But the code for Pizza is in no way dependent on the code for, or even the existance of, a GUI.

weyy wow thanks a lots james much appreciated

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.