简体   繁体   English

明确调用按钮的actionPerformed()

[英]calling actionPerformed() of a button explicitly

I have one class where there are certain swing components. 我有一堂课,那里有某些挥杆组件。 In second class (as per requirement), I need to simulate the button click event ultimately calling the actionPerformed(ActionEvent ae) . 在第二堂课中(根据要求),我需要模拟按钮click事件,最终调用actionPerformed(ActionEvent ae) This button is in the first class(described in the first line). 此按钮在第一类中(在第一行中描述)。

How do I do so? 我该怎么做?

I have tried to go through the fireActionPerformed(ActionEvent ae) . 我试图通过fireActionPerformed(ActionEvent ae) However, I am unable to come to a solution. 但是,我无法解决。 A small snippet (as an example) would be very much helpful. 一个小片段(例如)将非常有帮助。

EDIT Note: I also need to disable the button, when I click it or simulate its click. 编辑注意:单击或模拟其单击时,我还需要禁用该按钮。

Pardon me if this has already been asked before. 请原谅我是否已经问过这个。 Though I have searched for similar question before. 尽管我之前已经搜索过类似的问题。

Thanks and Regards. 谢谢并恭祝安康。

JButton有doClick()方法,但是最好定义一个doMyAction()方法并从两个地方调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM