Method is not called inside the action listener me

2019-02-21 09:00发布

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条回答
太酷不给撩
2楼-- · 2019-02-21 09:49

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
    } 
  }
}
查看更多
登录 后发表回答