Loading...
Logo
Processing Forum
I'm making a program where I can make pictures using circles. I've got the duplicating of the circles down packed using the left click, but I want to remove them when I right click on the circles. Below I've got the code there to create them using the left mouse click but I'm not sure what code I would put in there to remove them, help?

void mousePressed() 
{
  if (mouseButton == LEFT) {
  int t = Balls.size();
  for( int i=0; i < t; i++)
    Balls.get(i).dragging();
  } else {
    
  }
}

Replies(4)

You can use List's method remove(index) to delete an element number #index from it.
However, inside a loop, it has to have a backwards iteration!

Of course, to find out the correct index to remove, you have to check an object's screen location 
to decide whether that 1 was right-clicked to be removed!
You can create a new check method for it inside the class.
Well I have a grid, I have a permanent row of circles across the bottom of the grid and when I left click on any of the circles I can drag them and place them anywhere on the grid, how would I find the correct index in that situation?
The same way you find the correct one to drag w/ left-click!
But instead of dragging it, you use remove() on it!

If you are indeed inside a loop, you had to use method get(index) to operate over an object's instance anyways!
Just remember to use a backwards loop! Where its iterator starts w/ maximum value and ends when reaches 0.

You can find an example of me using it @ this post below on program Multiple Bullets:

"} else {"
If not LEFT click, it is not necessarily a RIGHT click! Lot of mouse buttons today have at least three buttons. Ie. you can also have MIDDLE cliick...