I'm trying to make an section of code in mouseClicked remove any rectangles clicked on from a Vector. All the rectangles are properly stored in the vector and the point I'm checking for is valid when I run the program. Looking at the documentation, there is indeed a rectangle.contains(point)
method, so i'm not sure why the following snippet is invalid. Thanks!
public void mouseClicked(MouseEvent m)
{
Point p = new Point(m.getPoint());
Vector v = ball.r; //ball.r is where they are put into in another object's method
boolean done = false;
int i = 0;
while (!done)
{
if(v.elementAt(i).contains(p))
{
v.removeElement(i);
i--; //prevent i from incrementing
}
i++;
}
}
Also I did not do this in a for loop because, as far as I know, when an element is removed, the vector will "repack" and I will jump over an element of the vector. Not sure if I am right or wrong in saying/doing this.