Reputation: 189
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
Upvotes: 12
Views: 7134
Reputation: 205785
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.
Upvotes: 6