java swing 如何通过按钮的事件监听器实现在一个窗口中显示不同的内容,大神给看看
/***Createtheframe.*/publicTest(){setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setB...
/**
* Create the frame.
*/
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setText("\u7B2C\u4E00\u4E2A\u6309\u94AE\u663E\u793A\u5185\u5BB9");
textField.setBounds(71, 75, 108, 51);
contentPane.add(textField);
textField.setColumns(10);
JButton btnNewButton = new JButton("\u6309\u94AE1");
btnNewButton.setBounds(73, 172, 93, 23);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("\u6309\u94AE2");
btnNewButton_1.setBounds(211, 172, 93, 23);
contentPane.add(btnNewButton_1);
textField_1 = new JTextField();
textField_1.setText("\u7B2C\u4E8C\u4E2A\u663E\u793A\u7684\u5185\u5BB9");
textField_1.setBounds(207, 75, 129, 51);
contentPane.add(textField_1);
textField_1.setColumns(10);
}
} 展开
* Create the frame.
*/
public Test() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
textField = new JTextField();
textField.setText("\u7B2C\u4E00\u4E2A\u6309\u94AE\u663E\u793A\u5185\u5BB9");
textField.setBounds(71, 75, 108, 51);
contentPane.add(textField);
textField.setColumns(10);
JButton btnNewButton = new JButton("\u6309\u94AE1");
btnNewButton.setBounds(73, 172, 93, 23);
contentPane.add(btnNewButton);
JButton btnNewButton_1 = new JButton("\u6309\u94AE2");
btnNewButton_1.setBounds(211, 172, 93, 23);
contentPane.add(btnNewButton_1);
textField_1 = new JTextField();
textField_1.setText("\u7B2C\u4E8C\u4E2A\u663E\u793A\u7684\u5185\u5BB9");
textField_1.setBounds(207, 75, 129, 51);
contentPane.add(textField_1);
textField_1.setColumns(10);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询