title: My KeyListener can't read key inputs
body: <p>Right now, I have a class that extends <code>JPanel</code> and implements <code>KeyListener</code>. I've instantiated this class to another class that runs it in my loop. The KeyListener class looks like</p>
  
  <pre><code>public class Keyboard extends JPanel implements KeyListener{
  
  
  public Keyboard()
  {
           this.addKeyListener(this);
  }
  
      public void update()
  {
  
  }
  
  @Override
  public void keyPressed(KeyEvent e)
  {   
  
              if(keyCode == KeyEvent.VK_S){
                   System.out.println("Made it");
              }
  }
  
  
  @Override
  public void keyReleased(KeyEvent e)
  {
  }
  
  @Override
  public void keyTyped(KeyEvent e)
  {
  }
  }
  </code></pre>
  
  <p>I implemented this in another class that utilizes a <code>MouseListener</code> just fine in the <code>Game</code> class. But for some reason, it won't listen to the keyboard.</p>
  
  <pre><code>public class Main
  
  {
  
  public static final int WIDTH = 640;
  public static final int HEIGHT = 640;
  public static final String NAME = "Game";
  
  private static BufferedImage image;
  private static Graphics2D g;
  private static boolean forceQuit;
  
  private static Game game;
      private static Keyboard keyboard;
  
      public Main(){
  
      }
  
  private static void init()
  {
      image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
      g = (Graphics2D) image.getGraphics();
      g.setBackground(Color.BLACK);
  
      game = new Game();
              keyboard = new Keyboard();
  }
  
  private static void start()
  {
      run();
  }
  
  public static void stop()
  {
      forceQuit = true;
  }
  
  public static void run()
  {
      @SuppressWarnings("unused")
      int frames = 0;
  
      double unprocessedSeconds = 0;
      long lastTime = System.nanoTime();
      double secondsPerTick = 1.0 / 60.0;
      int tickCount = 0;
  
      while (!forceQuit)
      {
                  if(keyboard.isSwampland()){
                      game.setSwampland(true);
                  }
  
          long now = System.nanoTime();
          long passedTime = now - lastTime;
          lastTime = now;
          if (passedTime &lt; 0)
              passedTime = 0;
          if (passedTime &gt; 100000000)
              passedTime = 100000000;
  
          unprocessedSeconds += passedTime / 1000000000.0;
  
          boolean ticked = false;
          while (unprocessedSeconds &gt; secondsPerTick)
          {
              game.update();
                              keyboard.update();
              unprocessedSeconds -= secondsPerTick;
              ticked = true;
  
              tickCount++;
              if (tickCount % 60 == 0)
              {
                  // System.out.println("FPS:" + frames);
                  lastTime += 1000;
                  frames = 0;
              }
          }
  
          if (ticked)
          {
              game.render(g);
  
              Graphics gg = game.getGraphics();
              gg.drawImage(image, 0, 0, null);
              gg.dispose();
  
              frames++;
          }
          else
          {
              try
              {
                  Thread.sleep(1);
              }
              catch (InterruptedException e)
              {
                  e.printStackTrace();
              }
          }
  
  
  
      }
  }
  
  public static void main(String[] args)
  {
      Main.init();
  
      JFrame frame = new JFrame(NAME);
      frame.setDefaultCloseOperation(3);
      frame.setContentPane(game);
      frame.pack();
      frame.setLocationRelativeTo(null);
      frame.setVisible(true);
  
      Main.start();
  }
  
  }
  </code></pre>