How to get the data reference/index in Linked list?
e.g. if I have this linked list
java.util.List<Polygon> triangles = new LinkedList<Polygon>();
polygon triangle, selectedTriangle;
Point startDrag,endDrag,midPoint;
....
triangles.add( new Polygon(xs, ys,3));
e.g. How can I set the Polygon selectedTriangle as the same with one of the existing triangle in the linked array list?
EDITED:
java.util.List<Polygon> triangles = new LinkedList<Polygon>();
polygon triangle, selectedtriangle;
....
triangles.add( new Polygon(xs, ys,3));
.....
public void mousePressed(MouseEvent e) {
....
startDrag = new Point(e.getX(), e.getY());
endDrag = startDrag;
for (Polygon p : triangles) {
if (p.contains(startDrag)) {//inside triangle
//I dont know how to set the selectedTriangle as the same with existing triangle
selectedTriangle = triangles.indexOf(p.contains(startDrag));
break; //
}
}
.....
}