title: Java JFrame - Key presses dont seem to be registering
body: <p>I am using Java AWT Graphics and JFrame to make a gui application. I need to get key input, and the KeyListener implementation does not seem to be working, as my <code>System.out.println("hello")</code> Does not seem to be triggering. I cannot find an answer for this problem elsewhere on the internet so i have come here. </p>
  
  <p>I am using eclipse and itdoes not seem to provide me with any insight, errors, warnings ect relating to the problem, I am also rather new to Java but i have experience with higher level languages including JavaScript.</p>
  
  <p>Other than the forementioned problem, the application works as intended, moving the rectangle from the top left, to the top right of the screen and beyond.</p>
  
  <pre><code>import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Toolkit;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.Timer;
  
  public class Main extends JPanel implements ActionListener, KeyListener{
  
      static int WIDTH;
      static int HEIGHT;
  
      int x = 0;
      int y = 0;
  
      int targetFPS = 60;
      int currentFPS = targetFPS;
  
      Timer timer = new Timer(1000/targetFPS, this);
  
      public Main(){
          timer.start();
          addKeyListener(this);
          setFocusable(true);
          setFocusTraversalKeysEnabled(false);
      }
      public void paintComponent(Graphics g){
          super.paintComponent(g);
          g.fillRect(x-25, y-25, 50, 50);
      }
      public static void main(String[] args){
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
          WIDTH = (int) screenSize.getWidth();
          HEIGHT = (int) screenSize.getHeight();
          Main main = new Main();
          JFrame frame = new JFrame();
          frame.setTitle("Hello");
          frame.setSize(WIDTH, HEIGHT);
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(main);
      }
      @Override
      public void actionPerformed(ActionEvent e) {
          x++;
          repaint();
      }
      @Override
      public void keyPressed(KeyEvent e) {
          int c = e.getKeyCode();
          System.out.println("hello");
      }
      @Override
      public void keyReleased(KeyEvent e) {
  
      }
      @Override
      public void keyTyped(KeyEvent e) {
  
      }
  }
  </code></pre>