在java swing中,方法没有在动作监听器方法中被调用。[英] Method is not called inside the action listener method in java swing

问题描述

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

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

推荐答案

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

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://www.itbaoku.cn/post/978671.html