Vote count:
0
Hi I want to be able to receive input from the keyboard by the user but I've added everything I thought would allow my program to do this and still it does not work. What am I doing wrong?
class KeyInput implements KeyListener {
public void keyPressed(KeyEvent e) {
System.out.println("keyPressed");
}
public void keyReleased(KeyEvent e) {
System.out.println("keyReleased");
//System.out.println(e.getKeyChar());
}
public void keyTyped(KeyEvent e) {
System.out.println("keyTyped");
//System.out.println(e.getKeyChar());
}
}
public GameView() {
this.addKeyListener(new KeyInput());
}
The constructor works fine and KeyInput is an inner class of the GameView object. When running the game, if I press a key nothing gets printed to the system output. Am I missing something? Thanks!
asked 1 min ago
KeyListener is not working in Java
Aucun commentaire:
Enregistrer un commentaire