我自己,我总是使用
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.