Java Swing: Using ActionMap

那年仲夏 提交于 2019-12-19 13:46:25

问题


I've seen a post earlier that recommends favoring Actions over listeners. I am not so familiar with the ActionMap. What are the disadvantages of the each approach? I like to make inner classes that implement listeners. Is that a bad practice?

Thanks


回答1:


Key bindings rely on actions. There is a potential risk that Action "implementations tend to be more expensive in terms of storage than a typical ActionListener." In practice, the problem does not arise. Here is an example.

Using KeyListener is conceptually easier to understand but typically more difficult to maintain. One inevitably ends up re-creating some kind of binding machinery. This example, while instructive and even appropriate for a game, is needlessly complex.



来源:https://stackoverflow.com/questions/7253712/java-swing-using-actionmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!