Ho provato sia con il seguente codice, posto dentro l'init:
addKeyListener(new KeyAdapter(){
@Override
public void keyPressed(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_DOWN:break;
case KeyEvent.VK_UP:break;
case KeyEvent.VK_LEFT:sx=true;break;
case KeyEvent.VK_RIGHT:dx=true;break;
}
repaint();
}
@Override
public void keyReleased(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_DOWN:break;
case KeyEvent.VK_UP:break;
case KeyEvent.VK_LEFT:sx=false;break;
case KeyEvent.VK_RIGHT:dx=false;break;
}
repaint();
}
@Override
public void keyTyped(KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_DOWN:break;
case KeyEvent.VK_UP:break;
case KeyEvent.VK_LEFT:sx=true;break;
case KeyEvent.VK_RIGHT:dx=true;break;
}
repaint();
}
});
sia con:
public boolean keyDown(Event e, int click){
switch(click){
case Event.RIGHT:dx=true;break;
case Event.LEFT:sx=true;break;
case Event.DOWN:break;
case Event.UP:break;
}
repaint( );
return true;
}
public boolean keyUp(Event e, int click){
switch(click){
case Event.RIGHT:dx=false;break;
case Event.LEFT:sx=false;break;
case Event.DOWN:break;
case Event.UP:break;
}
repaint( );
return true;
}
sia implementando con keylistener la classe, che già eredita dall'applet e che è implementata cn Runnable e ActionListener...spero di esserti stato d'aiuto.