0

I am doing a program that deals with customers going in the restaurant and ordering food using said program. On the first frame, it asks the customer what is his/her name and on the second frame, it will ask what are the orders. I've already built 5 frames and the final frame should display a summary of his orders and that includes the total amount the customer needs to pay and his/her name. How can I achieve that?

I'm only a beginner when it comes to coding and I might not know some of the terms that you will use so please be gentle. ^_^

Here are frames 1 and 2 and 5. I think this should be enough because frames 2, 3, and 4 are very similar. Frame2 is for the food, Frame3 is for the drinks, and Frame4 is for desserts. Take note that Frame5 is still not finished and might change depending on your answers. Please help me.

Frame1.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class Frame1 extends JFrame implements ActionListener {

    FlowLayout fl=new FlowLayout();
    JLabel lb1=new JLabel("WE WELCOME YOU TO THE FINEST RESTAURANT IN TOWN!");
    JButton b1=new JButton("Start!");
    Icon ic1=new ImageIcon("logo.jpg");
    JTextField tf1=new JTextField(10);
    JLabel lb2=new JLabel(ic1);
    JLabel lb3=new JLabel("Please press next to start ordering. ");



    public Frame1() {
        super("CHIONG'S 2 GO ORDERING SYSTEM");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setSize(500,200);
        setLocationRelativeTo(null);

        setLayout(fl);
        add(lb2);
        add(lb1);
        add(lb3);
        add(tf1);
        add(b1);
        b1.addActionListener(this);

        setVisible(true);

    }

    public void actionPerformed(ActionEvent e) {
        setVisible(false);
        Frame2 f2=new Frame2();

    }

    public static void main(String[] args) {
        Frame1 f1=new Frame1();
    }


}

Frame2.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Frame2 extends JFrame implements ActionListener{
    FlowLayout fl=new FlowLayout();
    Icon ic1=new ImageIcon("logo.jpg");
    JLabel lb2=new JLabel(ic1);

    JCheckBox menu1=new JCheckBox("Adobo - 50", false);
    JCheckBox menu2=new JCheckBox("Chicken Nuggets - 50", false);
    JCheckBox menu3=new JCheckBox("Chicken, Bacon, and Spinach Spaghetti - 70", false);
    JCheckBox menu4=new JCheckBox("Salt-and-Pepper Chicken with Spring Quinoa Pilaf - 70", false);
    JCheckBox menu5=new JCheckBox("Chipotle Chicken Fajitas - 70", false);
    JCheckBox menu6=new JCheckBox("Green Bean-and-Barley Chicken Casserole - 70", false);
    JCheckBox menu7=new JCheckBox("Roasted Chicken and Winter Squash - 70", false);
    JCheckBox menu8=new JCheckBox("Chicken and Corn Bread Pancakes with Spicy Syrup - 80", false);
    JCheckBox menu9=new JCheckBox("Skillet Chicken with Creamy Cilantro Lime Sauce - 80", false);
    JCheckBox menu0=new JCheckBox("Greek Chicken with Tomato-and-Rice Salad - 80", false);
    JLabel lb1=new JLabel("                                   ");
    JButton jb0=new JButton("Back");
    JButton jb1=new JButton("Next");

    public Frame2() {
        super("Please select your order/s.");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(480,420);
        setLocationRelativeTo(null);
        setLayout(fl);
        add(lb2);

        add(menu1);
        add(menu2);
        add(menu3);
        add(menu4);
        add(menu5);
        add(menu6);
        add(menu7);
        add(menu8);
        add(menu9);
        add(menu0);
        //add(lb1);
        add(jb0);
        add(jb1);
        jb0.addActionListener(this);
        jb1.addActionListener(this);

        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand()=="Back") {
            this.dispose();
            Frame1 f1=new Frame1();
        } else {
            this.dispose();
            Frame3 f3=new Frame3();
        }
    }
}

Frame5.java

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Frame5 extends JFrame implements ActionListener {
    FlowLayout fl=new FlowLayout();
    Icon ic1=new ImageIcon("logo.jpg");
    JLabel lb2=new JLabel(ic1);

    //JCheckBox menu1=new JCheckBox("Thank you for ordering!", false);
    //JLabel lb3=new JLabel("                                         ");
    JLabel lb1=new JLabel("Thank you for ordering!!! Enjoy your meal and please come back again!!!");
    //JLabel lb0=new JLabel("                                                                   ");
    JButton jb0=new JButton("Back");
    JButton jb1=new JButton("Finish");

    public Frame5() {
        super("Thank you.");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(480,200);
        setLocationRelativeTo(null);
        setLayout(fl);
        add(lb2);
        //add(menu1);
        //add(lb3);
        add(lb1);
        //add(lb0);
        add(jb0);
        add(jb1);

        jb0.addActionListener(this);
        jb1.addActionListener(this);

        setVisible(true);
    }

    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand()=="Back") {
            this.dispose();
            Frame4 f4=new Frame4();
        } else {
            this.dispose();
            Frame1 f1=new Frame1();
        }
    }
}
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
Marion
  • 13
  • 6
  • 3
    *"I've already built 5 frames"* - [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice), I'd recommend using a `CardLayout` instead, see [How to Use CardLayout](http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html). *"The final frame should display a summary of his orders and that includes the total amount the customer needs to pay and his/her name. How can I achieve that?*" - This suggests you need a model of some kind which can store all the information you need to collect between views – MadProgrammer Mar 13 '16 at 05:19
  • 1
    Maybe have a look at [Model-View-Controller](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller) – MadProgrammer Mar 13 '16 at 05:19
  • @MadProgrammer thank you very much for your reply. looks like the cardlayout is very good to use in this kind of situation, unfortunately, i don't have enough time to study and write a code from scratch as my skill is not yet that good because the deadline of this project (school project) is tomorrow. Based on your comments, do you mean to say that it's not possible to bring what the user inputs on the first frame to the last frame using this kind of code? – Marion Mar 13 '16 at 05:50
  • @MadProgrammer i bookmarked your links so i can study them later btw. – Marion Mar 13 '16 at 05:52
  • *"..because the deadline of this project (school project) is tomorrow."* It seems the thing you most need is better time-management skills. "24 hours before it's due" is not the time to be bringing a problem to SO. Some people asking questions don't get the first answer or even comment in that amount of time. I prefer helping people with better time-management skills. Best of luck with it! – Andrew Thompson Mar 13 '16 at 13:23
  • @AndrewThompson good thing is I have figured it out on my own, thanks! – Marion Mar 13 '16 at 14:03

0 Answers0