加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 最好使用:Action vs ActionListener?

发布时间:2020-12-14 16:39:47 所属栏目:Java 来源:网络整理
导读:我自己,我总是使用 ActionListener 作为摆动事件处理程序(例如按钮单击),它是我在大多数摆动应用程序中看到的最常见的监听器. 但是,一些Swing专业人士在stackoverflow中经常建议使用 Action 而不是 ActionListener .这样做有什么好处? 解决方法 如果需要在
我自己,我总是使用 ActionListener作为摆动事件处理程序(例如按钮单击),它是我在大多数摆动应用程序中看到的最常见的监听器.

但是,一些Swing专业人士在stackoverflow中经常建议使用Action而不是ActionListener.这样做有什么好处?

解决方法

如果需要在组件之间共享功能,则首选操作.从 docs

if you have two or more components that perform the same function,consider using an Action object to implement the function.

但也说

An Action object is an action listener that provides not only action-event handling,but also centralized handling of the state of action-event-firing components such as tool bar buttons,menu items,common buttons,and text fields. The state that an action can handle includes text,icon,mnemonic,enabled,and selected status.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读