在java swing中的action侦听器方法内部不调用方法

我必须在java swing actionperformed方法中调用一个方法。 但是当我点击按钮时没有任何反应。 如何解决这个问题呢?

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

您需要向按钮添加动作侦听器才能响应click事件:

 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 } } }