Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't get KeyListeners to work

    I'm starting a java game, and I can't seem to get KeyListeners to respond. I've searched all over the web and used every example I've seen, and it doesn't work. I'm using a java.awt.Window object. The MouseListener I've implemented works just fine. Here is my sample code:

    win = new Window(new Frame(gd.getDefaultConfiguration()));

    win.setFocusable(true);

    win.addMouseListener
    (
    new MouseAdapter()
    {
    public void mousePressed(MouseEvent evt)
    {
    }
    }
    );

    win.addKeyListener
    (
    new KeyAdapter()
    {
    public void keyTyped(KeyEvent k)
    {
    System.out.println("Typed");
    }

    public void keyPressed(KeyEvent k)
    {
    System.out.println("Pressed");
    }

    public void keyReleased(KeyEvent k)
    {
    System.out.println("Released");
    }
    }
    );

    Any help would be appreciated.

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    the class implements both?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •