Archived

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

shtkn

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

Recommended Posts

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 this post


Link to post
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 this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites