aspose file tools
The moose likes Java in General and the fly likes Capturing KeyStrokes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Capturing KeyStrokes" Watch "Capturing KeyStrokes" New topic
Author

Capturing KeyStrokes

Kughan Paramalingam
Greenhorn

Joined: Mar 30, 2003
Posts: 9
Hey there,
Does anyone know How to capture multiple keystrokes with a single listener. I just want to capture key events for numbers 0 to 9 but don't want to provide seperate action listeners for each one. Currently my code looks something like this.....
for(i=0; i<=9; i++) {
KeyStroke keystroke = KeyStroke.getKeyStroke(KeyEvent.VK_0 + i, 0, true);
keystroke.setActionCommand(Integer.toString(i));
registerKeyboardAction(numberListener, keystroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
}
The number Listener is my sole action listener but for some reason java doesn't like the setActionCommand with a keystroke object. I tried this method for radio boxes and it works. If anyone has any ideas of fixing this or even a better approach
I'll be ever so grateful
Cheers
 
 
subject: Capturing KeyStrokes
 
Threads others viewed
Preventing the Windows logo key from activating the Windows Start menu...
Override Java Component keystrokes
capturing all keystroke??
Using ActionMap for HotKey mapping
Swing Key bindings
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture