KeyListeners vs Keybindings?

Go To StackoverFlow.com

1

Possible Duplicate:
Comparing functionality between KeyListeners and Key Bindings

I've been trying to use the KeyListener in my program in order to get the input for constructing a number. It doesn't work as far as I can tell even though i've fully implemented it but thats not the question :P.

Anyway, I searched the internet in order to see if I was doing something wrong and came across Keybindings which are apparently made to work with swing components as opposed to KeyListeners. Which would be better for just getting the input from the number keys?

2012-04-05 21:03
by Rendition


2

The Keylistener is an older interface from the AWT days, its still Ok to use it with swing but is more of a general listener. It binds to all keys.

KeyBindings are a bit different in that they specifically bind a specific action to a specific key and other keys remain unaffected. The upshot of this is if you are going to listen for any key then a KeyListener is appropriate or you will have to implement seperate KeyBindings all for all keys which is patently silly.

To avoid event handlers with big switch statements the KeyBinding exists.

2012-04-05 21:13
by krystan honour
Ads