title: How to create a class that implements mouseListener
body: <p>I want to create a class that implement mouseListener interface (this class will override all mouseListener methods) instead of override all the methods in the main class. When I tring to do so I get an error.</p>
  
  <p>This is my code:</p>
  
  <pre><code>import javax.swing.*;
  
  public class Game {
  
  
      public Game(){
          JFrame frame = new JFrame();
          frame.setSize(500,500);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.addMouseListener(new MyMouseListener());
  
      }
  
      public static void main(String[] args) {
          Game app = new Game();
      } 
  }
  </code></pre>
  
  <p>MyMouseListener code:</p>
  
  <pre><code>import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  
  
  
  public class MyMouseListener implements KeyListener{
  
      @Override
      public void keyTyped(KeyEvent e) {
      }
  
      @Override
      public void keyPressed(KeyEvent e) {
  
      }
  
      @Override
      public void keyReleased(KeyEvent e) {
  
      }
  
  
  }
  </code></pre>
  
  <p><strong>edit:</strong> I understand my problem was that I implement keyListener insteed of mouseListener in the class MyMouseListener so I changed this and MyMouseListener code is now:</p>
  
  <pre><code>public class MyMouseListener extends Game implements MouseListener{
  
  
  
      @Override
      public void mouseClicked(MouseEvent e) {
      }
  
      @Override
      public void mousePressed(MouseEvent e) {
  
      }
  
      @Override
      public void mouseReleased(MouseEvent e) {
  
      }
  
      @Override
      public void mouseEntered(MouseEvent e) {
  
      }
  
      @Override
      public void mouseExited(MouseEvent e) {
  
      }
  
  
  }
  </code></pre>