tags:

views:

44

answers:

1

This might be a stupid question but I write a class called test lets say in GWT and I want to have it listen for DOM events. How would I do that?

I have tried implementing lets say the KeyPressHandler and then implementing the method onKeyPress() and I place an Window.alert("Event") in the body. Though nothing happens when I test it pressing any key.

I have looked into the Google documentation here but I really though GWT made it very easy to get these DOM events.

Example

I have a player class and I want to incerment its x value when the user press the left arrow key. So I would impelment the KeyPresshanlder and the method onKeyPress(). Though this doesn't work, is there somthing more I need to do?

+1  A: 

You have to add that handler to a Widget that implements HasKeyPressHandlers - a common choice is wrapping your widget/player in a FocusPanel (it implements a lot of handlers - key, mouse, etc).

Igor Klimer