title: How to check if the key pressed was an arrow key in Java KeyListener?
body: <p>Can you help me refactor this code:</p>
  
  <pre><code>public void keyPressed(KeyEvent e)
      {
  
      if (e.getKeyCode()==39)
      {
                  //Right arrow key code
      }
  
      else if (e.getKeyCode()==37)
      {
                  //Left arrow key code
      }
  
      repaint();
  
  }
  </code></pre>
  
  <p>Please mention how to check for up/down arrow keys as well.Thanks!</p>