在java swing中的action侦听器方法内部不调用方法 [英] Method is not called inside the action listener method in java swing

查看:115
本文介绍了在java swing中的action侦听器方法内部不调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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();
    }
    }


推荐答案

你需要为你的按钮添加动作监听器以响应click事件:

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

这篇关于在java swing中的action侦听器方法内部不调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆