title: how to simply implement a KeyListener?
body: <pre><code>public class MyPanel extends JPanel implements KeyListener {
      private char c = 'e';
      public MyPanel() {
          this.setPreferredSize(new Dimension(500,500));
          addKeyListener(this);
      }
      public void paintComponent(Graphics g) {
          super.repaint();
          g.drawString("the key that pressed is" + c, 250,250);
      }
  
      public void keyPressed(KeyEvent e) {
          c=e.getKeyChar();
          repaint();
  
      }
  
      public void keyReleased(KeyEvent e) {
      }
  
  
      public void keyTyped(KeyEvent e) {
          c=e.getKeyChar();
          repaint();
      }
  
      public static void main(String[] s) {
          JFrame f=new JFrame();
          f.getContentPane().add(new MyPanel());
          f.pack();
          f.setVisible(true);
      }
  }
  </code></pre>
  
  <p>I tried reading <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/keylistener.html" rel="noreferrer">this</a> yet didnt mange to understand how to simply implement a KeyListener. so what do i need to change for this to work?</p>