Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Swing: Using 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?

Thanks

like image 396
Asaf Avatar asked Aug 31 '11 07:08

Asaf


1 Answers

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.

like image 115
trashgod Avatar answered Oct 21 '22 13:10

trashgod