Java Swing:使用ActionMap [英] Java Swing: Using ActionMap
问题描述
我之前看到一篇帖子建议赞成对侦听器进行操作。我对ActionMap不太熟悉。每种方法有哪些缺点?我喜欢制作实现监听器的内部类。这是一种不好的做法吗?
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?
谢谢
推荐答案
键绑定依赖于操作。 操作可能存在风险
实施在存储方面往往比典型的 ActionListener
更昂贵。在实践中,问题不会出现。以下是示例。
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.
使用 KeyListener
在概念上更容易理解,但通常更难以维护。一个人不可避免地最终会重新创造某种约束机制。这个示例虽然具有指导性,甚至适用于游戏,但却是不必要的复杂。
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.
这篇关于Java Swing:使用ActionMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!