File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Using ActionMap for HotKey mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Using ActionMap for HotKey mapping" Watch "Using ActionMap for HotKey mapping" New topic

Using ActionMap for HotKey mapping

Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
Anyone used ActionMap, InputMap and KeyStroke classes to map key strokes to gui actions and passed the exam??! I am not sure if Sun considers this design is something that a junior programmer can't understand.
As always, your opinions are greatly appreciated.
Adam Roberts
Ranch Hand

Joined: Mar 18, 2002
Posts: 71
Hmm. Ive never used it. Not like you really need to though. Its not like the GUI is complex(at least mine isn't). Two whole buttons on mine.

I suppose it would be a good thing to know though

Adam Roberts - SCJP2, SCJD<br />insert witty something here
Sai Prasad
Ranch Hand

Joined: Feb 25, 2002
Posts: 560
The code is not that hard. You just have to get the details ironed out. Below is the method defined in my search panel class, I use for KeyStroke mapping:

In my search panel controller, the inner class extends AbstractAction instead of implementing ActionInterface.

Mark is going to definitely say it is a overkill. Is it true Mark? I don't want to fail...please...
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Let's see I had 4 ActionListeners, 1 Focus Listener, and 1 ListSelectionListener
The FocusListener is just like your ActionMap and only took me 1 line of code that is using the basic Action/Listener pattern in java which every Junior programmer learns in the beginning.

But yours is not overkill. , and I mean that.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: Using ActionMap for HotKey mapping
It's not a secret anymore!