Reputation: 31
I have a class (myKeyListener) that extends keyListener and a I have a JFrame. I added keyListener to my JFrame and it worked fine. But I had to change it to applet, so I changed JFrame to JInternalFrame and added this to a JApplet. (I didn't change anything else) now the keyListener doesn't listen. what should I do?
Upvotes: 3
Views: 1012
Reputation: 324108
Don't use a KeyListener. Instead use KeyBindings which handle focus issues better and are used by all Swing components.
Upvotes: 2
Reputation: 1070
Ok so heres a solution, instead of adding the keylistener to the applet add it to a JPanel. So act like the JPanel was your JFrame and then just add the keylistener to the JPanel and then add the JPanel to the JApplet and it should work fine! Let me know if that gives you any trouble and ill help you out.
Upvotes: 1