avi*_*ash 1 java events swing jbutton actionlistener
我正在研究一些我需要从另一个函数调用actionlistner
一个残疾人的东西jbutton
.怎么做?
创建一个将由禁用的jbutton调用的新方法,编写将在单击按钮时执行的所有代码.你不能actionlistiner
以其他方式打电话.
...
JButton disButton = new JButton("Disabled");
disButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
//do not write any statement here
doSomething();
}
});
...
private void doSomething() {
//all action event execution code here
System.out.println("I am in the action listener");
}
....
//in the other method or another button click event call doSomething()
//even button is disables like
JButton Button = new JButton("Submit");
Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
doSomething();
}
});
//or from another method
public void method() {
doSomething();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
542 次 |
最近记录: |