對於我在Java類中的第二個編程任務,我們必須創建一個Pizza Shop菜單GUI。除了用於計算總成本的按鈕(「過程選擇」)之外,一切都出現在我的GUI上(包括選項,框,單選按鈕等)。以下是我的代碼:沒有出現在Swing 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);
}
}
}
我忘了在某處添加一些代碼嗎?我很難過。
你解決了嗎?你可以請接受最有幫助的答案: –