Method is not called inside the action listener method in java swing

不羁的心 提交于 2019-12-19 12:22:26

问题


I have to call a method inside the java swing actionperformed method. But when I click the button nothing happens. How to solve this problem?

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

回答1:


You need to add action listener to your button in order to respond to click event:

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


来源:https://stackoverflow.com/questions/14516878/method-is-not-called-inside-the-action-listener-method-in-java-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!