title: Why the KeyEvent doesn't working though implemented KeyListener interface?
body: <p>In the <code>KeyDemo</code> class i implements <code>KeyListener</code> but i can't understand why the <code>KeyEvent</code>s doesn't working. I'm pressing key's but nothing is happening. This is only a short <code>Demo</code> class of a big class. Someone help me to solve this problem.  </p>
  
  <pre><code>import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class KeyDemo extends JPanel implements KeyListener {
  
      public KeyDemo() {
          // TODO Auto-generated constructor stub
          addKeyListener(this);
      }
  
      @Override
      public void keyPressed(KeyEvent e) {
  
          switch (e.getKeyCode()) {
          case KeyEvent.VK_UP:
              System.out.println("moving up");
              break;
          case KeyEvent.VK_RIGHT:
              robot.moveRight();
              robot.setMovingRight(true);
              break;
          }
      }
  
      @Override
      public void keyReleased(KeyEvent e) {
  
          switch (e.getKeyCode()) {
          case KeyEvent.VK_UP:
              System.out.println("stop moving up");
              break;
          case KeyEvent.VK_LEFT:
              robot.stopLeft();
              break;
          }
      }
  
      @Override
      public void keyTyped(KeyEvent e) {
          // TODO Auto-generated method stub
  
      }   
  }
  </code></pre>
  
  <p>Main class:</p>
  
  <pre><code>public class Main{
      public static void main(String[] args){
          JFrame f = new JFrame();
          f.setSize(400, 400);
          f.setVisible(true);
          KeyDemo demo = new  KeyDemo();
          f.add(demo);
      }
  }
  </code></pre>