• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# [java] adding a keylistener (w/out textfields)

## Recommended Posts

shtkn    122
I''m trying to make a video game applet, but the applet cannot catch key events. I tried adding the keyListener to the applet and to the lightweight container (one listener at a time), but the applet cannot catch any key events. However, the lightweight container can catch mouse events, so I''m not too sure what I am doing wrong. Can someone please help? Thank you

##### Share on other sites
Guest Anonymous Poster
Hey there, I cant really help much without seeing the code but I can tell you what has caught me in the past. Did you register the keylisteners? I know its something stupid but the stupidest things are sometimes the worst =).

##### Share on other sites
Ghardoan    122
One thing you should check is whether or not your lightweight component has the focus. You can gain the focus by putting something like this in your lightweight component:

if (!hasFocus()) { requestFocus();}

Also, make sure you added your KeyListener using the add() method.

Hope this helps!

Ghardoan