2

Why do we have to use the extra object ActionMap?
What's the meaning?

Take this as an example:

imap.put(KeyStroke.getKeyStroke("ctrl Y"), "panel.yellow");

ActionMap amap = panel.getActionMap();

amap.put("panel.yellow", yellowAction);
mKorbel
  • 109,525
  • 20
  • 134
  • 319
scobur
  • 275
  • 2
  • 3
  • 9

1 Answers1

2

As shown in this example, an InputMap associates a KeyStroke with an abstract name that identifies the correspoding Action. The ActionMap uses that name as a key to evoke a particular Action instance's actionPerformed() method. As a concrete example, this ScrollTimer uses the ActionMap of a JScrollPane to look up actions by name and use them without direct access to the implementation.

Addendum: The abstraction was designed to support the "pluggable look and feel" (L&F) architecture describe here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045