方法不叫的Java Swing的动作监听器方法内(Method is not called insi

2019-07-18 16:46发布

我要调用的Java Swing actionPerformed方法中的方法。 但是,当我按一下按钮没有任何反应。 如何解决这个问题呢?

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

Answer 1:

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

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


文章来源: Method is not called inside the action listener method in java swing