...

View Full Version : Can't get KeyListeners to work



Emoboy7
02-01-2005, 08:44 PM
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.

ghell
02-02-2005, 10:40 AM
the class implements both?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum