public static Direction directionForArrowKey(KeyEvent e){
  int index=Math.max(0,Math.min(e.getKeyCode(),KeyEvent.VK_DOWN) - KeyEvent.VK_LEFT);
  return Direction.values()[index];
}

public static Direction directionForArrowKey ( KeyEvent e ) { int index = Math . max ( 0 , Math . min ( e . getKeyCode ( ) , KeyEvent . VK_DOWN ) - KeyEvent . VK_LEFT ) ; return Direction . values ( ) [ index ] ; }
returns a direction corresponding to the specified arrow key . if the event does not map to one of the 4 keyboard arrows , the returned direction will be either left or down .
