This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Capturing KeyStrokes

 
Kughan Paramalingam
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic