I'm assuming you commented out the MouseListener
because you were getting an error.
The thing is, when you implements MouseListener
, you need to @Override
all the methods, not just mouseClicked
public class StatTracker extends JPanel 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) {}
}
The ones you don't need you can just leave empty. Just add code to the mouseClicked
if that's all you need.
Also you need to call super.paintComponent(g)
in your paintComponent
method
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Also as you can see from my code, I use the @Override annotation. You should make a habit of doing this for methods you are attempting to override. If it is a successful override, you won't get an error. If it isn't then you will get an error.