对于我在 Java 课程中的第二个编程作业,我们必须创建一个 Pizza Shop 菜单 GUI。除了您应该单击以计算总成本的按钮(“流程选择”)之外,所有内容都出现在我的 GUI 上(包括选项、框、单选按钮等)。以下是我的代码:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class PizzaShop extends JFrame {
private Topping t;
private PizzaSize ps;
private PizzaType pt;
private JPanel buttonPanel;
private JButton ProcessSelection;
public PizzaShop() {
super("Welcome To Home Pizza Shop");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
t = new Topping();
ps = new PizzaSize();
pt = new PizzaType();
createPanel();
add(t, BorderLayout.NORTH);
add(ps, BorderLayout.WEST);
add(pt, BorderLayout.CENTER);
setVisible(true);
}
private void createPanel() {
buttonPanel = new JPanel();
ProcessSelection = new JButton("Process Selection");
ProcessSelection.addActionListener(new calButton());
buttonPanel.add(ProcessSelection);
}
private class calButton implements ActionListener {
public void actionPerformed(ActionEvent e) {
double subtotal;
subtotal = t.getTopping() + ps.getPizzaSize();
JOptionPane.showMessageDialog(null, "Your Order \n" + "Pizza Type" + pt.getPizzaType() + "\n" + "Amount Due" + subtotal);
}
}
private class ExitButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
}
我忘了在某处添加一些代码吗?我很困惑。