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

Started by
1 comment, last by shtkn 22 years, 3 months ago
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
Advertisement
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 =).
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

This topic is closed to new replies.

Advertisement