构造器
JButton() 创建一个空按钮
JButton(Sting text ) 创建一个按钮,按钮带有文本标签“text”,即给按钮命名text
JButton(Icon icon ) 创建一个按钮,按钮带有图标
方法
setEnable
public void setEnable(boolean b) 启用或禁用按钮,参数b传递true时,启用按钮,参数b传递false时,禁用按钮
addActionListener
public void addActionListener(ActionListener l) 添加监听事件,默认使用actionPerformed方法
例如:
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
StopThreadTest.this.startButton.setEnabled(false);
StopThreadTest.this.stopButton.setEnabled(true);
startThread();
}
};