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();
}
}
}