I have a subclass of JFrame
that uses a class extended from JPanel
public class HelloWorld extends JPanel implements KeyListener
I add an object of HelloWorld
to the frame - app.add(helloWorld);
. Now, when I press any keyboard key non of the KeyListener
methods gets called and it seems that helloWorld
doesn't have window focus. I have tried also to invoke helloWorld.requestFocusInWindow();
but still doesn't respond.
How can I make it respond to key press?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…