public void keyPressed(KeyEvent ev)
{
int keyCode = ev.getKeyCode();
if (keyCode == KeyEvent.VK_LEFT) ....;// your code
else if (keyCode == KeyEvent.VK_RIGHT) ......;// your code
else if (keyCode == KeyEvent.VK_UP) ........;//your code
else if (keyCode == KeyEvent.VK_DOWN) ........;//your code
}