title: Java Implementing ActionListener methods in Constructor
body: <p>Im trying to call my keyPressed method that I created (override) in my constructor for a game I am making to allow an object to move. I implemented ActionListener and KeyListener in the main class. </p>
  
  <p>Is this even possible? I tried calling the method by <code>this.keyPressed(KeyEvent e)</code> but I don't know how to initialize e.</p>
  
  <p>What would be the best way to do something like this? </p>
  
  <pre><code>Timer timer = new Timer(DELAY, this);
  public Game(Main game) {
  
      this.game = game;
      gamePanel = new GamePanel();
      buttonPanel = new JPanel();
      buttonPanel.add(startButton);
  
      this.addKeyListener(this);
      this.setFocusable(true); 
      this.setFocusTraversalKeysEnabled(false);
      this.getContentPane().add(gamePanel, BorderLayout.CENTER);
      this.getContentPane().add(buttonPanel, BorderLayout.PAGE_END);
      this.setSize(1000, 1000);
      this.setVisible(true);
  
  
  
  
  
      }
  
  }
  
  @Override
  public void keyTyped(KeyEvent e) {
      // TODO Auto-generated method stub
  
  }
  
  @Override
  public void keyPressed(KeyEvent e) {
  
      switch (e.getKeyCode()) {
      case KeyEvent.VK_UP:
          game.move("u");
          break;
  
      case KeyEvent.VK_DOWN:
          game.move("d");
          break;
  
      case KeyEvent.VK_RIGHT:
          game.move("r");
          break;
  
      case KeyEvent.VK_LEFT:
          game.move("l");
          break;
      }
  }
  @Override
  public void actionPerformed(ActionEvent e) {
  
      Object src = e.getSource();
  
      if (src == timer) {
          game.updateBoard();
          if (game.gameEnded()) {
              timer.stop();
              }
          repaint();
  
      } else if (src == startButton) {
  
          if (timer.isRunning()) {
              timer.stop();
          } else {
              timer.stop();
          }
      }
  }
  </code></pre>