title: Java Swing mouseClick not working
body: <p>I'm trying to get some code to run on Mouse clicks using the MouseListener.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>class TestingLayout extends JFrame implements MouseListener, MouseMotionListener{
  ...
    private JFrame w = new JFrame();
    private JPanel panel1 = new JPanel(new GridLayout(4,2),false);
  
    public TestingLayout(){
      addMouseListener(this);
      BoxLayout boxLayout = new BoxLayout(w.getContentPane(),BoxLayout.Y_AXIS);
      w.setLayout(boxLayout);
      w.add(panel1);
      w.setSize(800,600);
      w.setVisible(true);
      ...
    }
    ...
    @Override
    public void mousePressed(MouseEvent e){
      System.out.println("eh");
    }
  }
  </code></pre>
  
  <p>But when I click on the JFrame, it doesn't run my code.
  I can't seem to figure it out. One StackOverflow question references a MouseListener reference page that is no longer in existence unfortunately.</p>
  
  <p>All help appreciated.
  Thanks</p>