addKeyListener is NOT working

L

Lars Willich

When I press a key the keyPressed() procedure is NOT called. Why ?
In contrast the button events working successfully.

Possible the key-Event is not forwarded to the "outer" level.
How do I forward these events otherwise?


public class xxx extends JFrame implements ActionListener, KeyListener {
boolean inAnApplet = true;

public xxx() {

...
mybutton.addActionListener(this);
...
addKeyListener(this);
...
...
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if (inAnApplet) {
dispose();
} else {
System.exit(0);
}
}
});
}

public void keyPressed(KeyEvent e) {
System.out.println("In KeyPressed"); // never reached !!
... }

public void actionPerformed(ActionEvent e){
System.out.println("In ActPerf"); //reached !!
... }
}


public static void main(String args[]) {
...
xxx window = new xxx();
}

Lars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top