How to make a copy of a polygon using mouse click (e.g. when the mouse click, a menu pop up showing menu for copy).
I have problem to differentiate a mouse click, to draw or to copy. I created a method where when the user pressed the mouse, the method will check if the mouse pressed inside existing polygon or outside. If it outside polygon it will draw a new polygon. If it outside it will move the polygon. How am I able to copy the polygon?
.....
public void mousePressed(MouseEvent e) {
startDrag = new Point(e.getX(), e.getY());
endDrag = startDrag;
repaint();
for(Polygon p:triangles){
if(p.contains(startDrag)){ // if inside polygon triangle, mark the triangle
selectedTriangle = p;
break;
}
}
}
....
public void mouseClicked(MouseEvent e) {
startDrag = new Point(e.getX(), e.getY());
Polygon[] triArray = triangles.toArray(new Polygon[triangles.size()]);
if (e.getClickCount() ==2) {
for (Polygon p:triArray){
if (p.contains(startDrag)) {//Polygon has a 'contains(Point)'
triangles.remove (p);
break;
}
}
}