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,107
  • 18
  • 130
  • 305
scobur
  • 235
  • 2
  • 3
  • 8

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
  • 200,320
  • 28
  • 229
  • 974