I was wondering how to stop mousedMoved from being fired. I've been googling but can't find an answer. Is there a method for this? I'm using eclipse and went through the mouseevent methods but just can't find anything.
public class Drawing extends JPanel {
private ArrayList<Point> pointList;
private int counter = 0;
public Drawing() {
setLayout(new FlowLayout());
setBackground(Color.white);
pointList = new ArrayList<Point>();
addMouseListener(new MouseTrackerListener());
}
public void paintComponent(Graphics pen) {
super.paintComponent(pen);
for (int i = 0; i < pointList.size(); i++) {
Point p = pointList.get(i);
pen.fillOval(p.x, p.y, 10, 10);
}
}
private class MouseTrackerListener extends MouseInputAdapter {
public void mouseClicked(MouseEvent e) {
counter++;
if (counter % 2 != 0) {
addMouseMotionListener(new MouseTrackerListener());
} else {
System.out.println("Hi");
}
}
public void mouseMoved(MouseEvent e) {
Point point = e.getPoint();
pointList.add(point);
repaint();
}
}