addKeyListener is NOT working

Discussion in 'Java' started by Lars Willich, May 23, 2006.

  1. Lars Willich

    Lars Willich Guest

    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
    Lars Willich, May 23, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ratman
    Replies:
    0
    Views:
    640
    Ratman
    Sep 14, 2004
  2. Martin Heuckeroth
    Replies:
    5
    Views:
    665
    JiangZemin
    Apr 1, 2005
  3. Alan Silver
    Replies:
    1
    Views:
    3,750
    Alan Silver
    Aug 2, 2005
  4. gaurav tyagi
    Replies:
    14
    Views:
    1,303
    gaurav tyagi
    Jan 20, 2006
  5. Ron
    Replies:
    4
    Views:
    4,750
Loading...

Share This Page