PDA

View Full Version : KeyListener help


froggerhelp
08-01-2006, 07:00 PM
we're making a game and KeyListener isn't working. this is our code so far:

public class Frogger extends GraphicsProgram implements KeyListener
{
// instance variables
private Room myRoom;



public void init()
{
System.out.println("constructed frogger");
myRoom = new Room (400, 350, getGCanvas ());
this.setFocusable(true);
this.addKeyListener(this);
}

public void keyReleased(KeyEvent e){System.out.println(e.getKeyCode());}

public void keyTyped(KeyEvent e)
{
System.out.println(e.getKeyCode());
}

public void keyPressed (KeyEvent e)
{
System.out.println("key pressed");
if (e.getKeyCode() == KeyEvent.VK_DOWN)
{
myFrog.keyPressed(e);
}

if (e.getKeyCode() == KeyEvent.VK_UP)
{
myFrog.keyPressed(e);
}

if (e.getKeyCode() == KeyEvent.VK_LEFT)
{
myFrog.keyPressed(e);
}

if (e.getKeyCode() == KeyEvent.VK_RIGHT)
{
myFrog.keyPressed(e);
}
}


public void run ()
{
myRoom.run ();
System.out.println("WTM");
}


}

tricolaire
08-10-2006, 02:51 AM
what happens when you run the program?

what do you want to happen?

are there any error messages?