简体   繁体   中英

Key event not captured in Applet AFTER I've pressed one of my GUI buttons

I have music Applet which uses keyboard, mouse and GUI buttons. When applet is first loaded keyboard events work fine, as do mouse events. However, after I have pressed one of my GUI buttons the mouse events still work but the keyboard events don't, and don't start working again until I refresh the applet.

After hunting around on the net I found some posible solutions, I've tried adding button.setFocusable(true); and button.addKeyListener(this); to all my buttons, and and my panels. No effect at all. I've seen recommendations for converting to a JApplet and using key binding, but surely there must be a simpler way? Sorry for the lack of code, I've been working on this project since I was a newbie and it's a bit of a mess, and very long!

Any help much appreciated!

button.setFocusable(true); and button.addKeyListener(this); to all my buttons

For JButton use Swing Action or default implementations for ActionListener , rather than KeyBindings (for Swing based Container and JComponents), nor using KeyListener

EDIT

if isn't there really important reasons, don't use prehistoric AWT Applet , use JApplet , may be sufficient would be plain JFrame

Try to cut the problem area out of your project and put it here. Its highly probable, than while localizing the problem area you'll find some errors already.

If your project is a mess already, then the first and the most important thing you should do, is to order it. If it is a mess for you, that means you don't understand it. So, it simply can't work. That is your first and main error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM