addKeyListener(new KeyAdapter(){
@Override
public void keyPressed(KeyEvent event){
int keyPressed=event.getKeyCode();
swith(keyPressed){
case KeyEvent.VK_UP:
y-=5;
break;
case KeyEvent.VK_DOWN:
y+=5;
break;
case KeyEvent.VK_LEFT:
x-=5;
break;
case KeyEvent.VK_RIGHT:
x+=5;
break;
}
}
});