user827703
user827703

Reputation: 31

KeyListener doesn't work in JApplet

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

Answers (2)

camickr
camickr

Reputation: 324108

Don't use a KeyListener. Instead use KeyBindings which handle focus issues better and are used by all Swing components.

Upvotes: 2

gsfd
gsfd

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

Related Questions