title: KeyListener in JPanel not working (panel is focused)
body: <p>As the title says I'm trying to make add a keylistener to a JPanel. So far the only way I got it working was by adding an empty textfield and clicking on it. Now I don't want an empty textfield in my JPanel so I want to add the keylistener to the panel itself.</p>
  
  <p>Here is the class I'm talking about:</p>
  
  <pre><code>package cookieClicker;
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.Rectangle;
  import java.awt.event.KeyListener;
  import java.awt.event.MouseListener;
  
  import javax.swing.ImageIcon;
  import javax.swing.JPanel;
  import javax.swing.JTextField;
  
  public class CookieView extends JPanel
  {
      private CookieModel cm;
      private ImageIcon cookie;
      public Rectangle rect;
  
      public CookieView(CookieModel cm)
      {
          this.cm = cm;
          this.setFocusable(true);
          this.requestFocusInWindow();
      }
  
      public void paintComponent(Graphics g)
      {
          super.paintComponent(g);
          cookie = new ImageIcon("Untitled-1.png");
          g.setColor(Color.ORANGE);
          g.drawImage(cookie.getImage(), this.getWidth() / 2 - 100, this.getHeight() / 2 - 100, 200, 200, this);
          rect = new Rectangle(this.getWidth() / 2 - 100, this.getHeight() / 2 - 100, 200, 200);
      }
  
      public void addListener(MouseListener m, KeyListener k)
      {
          this.addMouseListener(m);
          this.addKeyListener(k);
      }
  }
  </code></pre>
  
  <p>Does anyone know how to make this work?</p>