+ 1

why this doesn t work?

this is the code package controles; import java.awt.event.KeyListener; public final class teclado implements KeyListener{ private final static int numTeclas = 120; private final boolean[] teclas = new boolean[numTeclas]; public boolean arriba; public boolean abajo; public boolean izquierda; public boolean derecha; public void actualizar(){ arriba = teclas[KeyEvent.VK_W]; abajo = teclas[KeyEvent.VK_S]; izquierda = teclas[KeyEvent.VK_A]; derecha = teclas[KeyEvent.VK_D]; } public void KeyPressed(KeyEvent e){ teclas[e.getKeyCode()] = true; } public void KeyReleased(KeyEvent e){ teclas[e.getKeyCode()] = false; } public void KeyTyped(KeyEvent e){ } } the error is that keyevent does not recognize i don t know why

6th Mar 2017, 3:53 PM
Ismael Perbech
Ismael Perbech - avatar
2 Respostas
0
A simile suggestion: debug. Put a breakcode into KeyPressed method to see the value of "e"
6th Mar 2017, 7:30 PM
Giampaolo Bolzonella
Giampaolo Bolzonella - avatar
0
' ok thnx
6th Mar 2017, 7:31 PM
Ismael Perbech
Ismael Perbech - avatar