How to use KeyListener
问题 I am currently trying to implement a keylistener in my program so that it does an action when I pressed an arrow key, the object in my program either moves left or right. Here is the moving method in my program public void moveDirection(KeyEvent e) { int move = 0; int r = K.getRow(); int c = K.getCol(); if (e.getKeyCode() == 39) move = 1; //KeyEvent.VK_RIGHT if (e.getKeyCode() == 37) move = 2; //KeyEvent.VK_LEFT //if (e.getKeyCode() == KeyEvent.VK_DOWN) move = 3; switch (move) { case 1: if