Something very weird is happening when I use the method :
public void mouseClicked(MouseEvent evt)
I count the number of clicks , and each time that I have one click or two clicks , I grab the (x,y) coordinate and add that coordinate to my list . But when I check the given picture , I see that the added coordinates are also dragged coordinates , i.e. , locations where the user has passed with the mouse , but didn't hit a click or double click .
How can that be ?
This questions is associated with my previous questions regarding polygons , and this problem seems to be the cause of my problems .
Here are the pictures : Closing a polygon
:
and when I start to draw something else :
Meaning is , that's the same polygon , only this time the coordinates where the mouse traveled but DIDN'T hit a click / double click , were also counted .
And that's my previous question .
Any idea would to the source of the problem would be greatly appreciated .
The code :
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.ArrayList;
import java.util.Iterator;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author X2
*
*/
public class Poly
{
public static void main (String[] args)
{
JFrame frame = new JFrame("Draw polygons");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new DrawingPanel());
frame.pack();
frame.setVisible(true);
}
}
Thanks