如果我按所示注释代码,JButtons 就会消失
public class analisi_spesa {
public static void main(String[] args) {
JFrame mainFrame = new JFrame("Java SWING Examples");
mainFrame.setSize(400,400);
mainFrame.setLayout(new GridLayout(3, 1));
/*
JLabel headerLabel = new JLabel("headerLabel",JLabel.CENTER );
JLabel statusLabel = new JLabel("statusLabel",JLabel.CENTER);
statusLabel.setSize(350,100);
*/
mainFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
JPanel controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
/*
mainFrame.add(headerLabel);
mainFrame.add(controlPanel);
mainFrame.add(statusLabel);
*/
mainFrame.setVisible(true);
// headerLabel.setText("Control in action: Button");
JButton okButton = new JButton("OK");
JButton submitButton = new JButton("Submit");
JButton cancelButton = new JButton("Cancel");
okButton.setActionCommand("OK");
submitButton.setActionCommand("Submit");
cancelButton.setActionCommand("Cancel");
okButton.addActionListener(new ButtonClickListener());
submitButton.addActionListener(new ButtonClickListener());
cancelButton.addActionListener(new ButtonClickListener());
controlPanel.add(okButton);
controlPanel.add(submitButton);
controlPanel.add(cancelButton);
mainFrame.setVisible(true);
}
}
我希望他们显示出来,因为我不评论代码。我从https://www.tutorialspoint.com/swing/swing_event_handling.htm拿了这个例子 谢谢大家,我正在等待答案。
万千封印
ITMISS
弑天下
跃然一笑
随时随地看视频慕课网APP
相关分类