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?
Asked
Active
Viewed 1,009 times
3
-
3Either answer to this [question](http://stackoverflow.com/questions/6728389/java-animation-with-key-listener-problem/6728534#6728534) may prove helpful. – trashgod Jul 18 '11 at 21:03
-
2can you provide an SSCCE please? – Martijn Courteaux Jul 18 '11 at 21:09
-
Make sure your component (or some subcomponent of it) actually has the focus. – Paŭlo Ebermann Jul 18 '11 at 21:32
2 Answers
2
Don't use a KeyListener. Instead use KeyBindings which handle focus issues better and are used by all Swing components.

camickr
- 321,443
- 19
- 166
- 288
1
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.

gsfd
- 1,070
- 2
- 12
- 17