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();
}