用eclipse编辑时,定义一个JBtton事件JButton声明是:privateJButtonbutton=newJButton();privateJButtonbutton_1=newJButton();privateJButtonbutton_2=newJButton();privateJButton...
用eclipse编辑时,定义一个JBtton事件
JButton 声明是:
private JButton button = new JButton();
private JButton button_1 = new JButton();
private JButton button_2 = new JButton();
private JButton button_3 = new JButton();
private JButton button_4 = new JButton();
如:
JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
button_actionPerformed(event);
}
});
button.setFont(new Font("宋体", Font.PLAIN, 12));
button.setBackground(SystemColor.control);
button.setText("添加");
button.setBounds(10, 420, 70, 28);
getContentPane().add(button);
并在后面定义了方法:
// button 方法 增加
public void button_actionPerformed(ActionEvent event) {
button_1.setEnabled(false);
button_2.setEnabled(false);
button_3.setEnabled(true);
button_4.setEnabled(true);
}
在写代码时都没错,但是运行是点击 button 时却没有产生
禁用 button_1 button_2
也没启用 button_3 button_4
展开