我正在做一个程序,处理客户进入餐厅并使用该程序订购食物。在第一帧,它询问客户他/她的名字是什么,在第二帧,它将询问订单是什么。我已经构建了5个框架,最后一个框架应该显示他的订单摘要,其中包括客户需要支付的总金额和他/她的名字。我怎样才能做到这一点?
在编码方面,我只是一个初学者,我可能不会知道你会使用的一些术语,所以请保持温和。 ^ _ ^
以下是第1帧和第2帧以及第5帧。我认为这应该足够了,因为第2,3和4帧非常相似。 Frame2用于食物,Frame3用于饮料,Frame4用于甜点。请注意,Frame5仍未完成,可能会根据您的答案而改变。请帮帮我。
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();
}
}
}