-2

我必须在 java swing actionperformed 方法中调用一个方法。但是当我单击按钮时,什么也没有发生。如何解决这个问题呢?

       private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
   {
    hellocalled();
    }
    }
4

1 回答 1

6

您需要为按钮添加动作侦听器以响应点击事件:

Button b = new Button();
b.addActionListener(new ActionListener(){

    public void actionPerformed(ActionEvent evt){
       jButton1ActionPerformed(evt);
       // call the method jButton1ActionPerformed
       // or you can call the one you have defined `hellocalled();` here
    } 
  }
}
于 2013-01-25T07:05:14.707 回答