#     This is the code that I have written so far. When the mouse is clicked, objects will appear but I want the program structured, in which if the mouse is pressed again on an object, the object will delete.           

**URL:** https://discourse.processing.org/t/this-is-the-code-that-i-have-written-so-far-when-the-mouse-is-clicked-objects-will-appear-but-i-want-the-program-structured-in-which-if-the-mouse-is-pressed-again-on-an-object-the-object-will-delete/35348
**Category:** Processing
**Created:** [February 21, 2022, 2:55am UTC](https://discourse.processing.org/t/this-is-the-code-that-i-have-written-so-far-when-the-mouse-is-clicked-objects-will-appear-but-i-want-the-program-structured-in-which-if-the-mouse-is-pressed-again-on-an-object-the-object-will-delete/35348 "2022-02-21T02:55:48Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![erijgeirg](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@erijgeirg](https://discourse.processing.org/u/erijgeirg)
#### Post date: [February 21, 2022, 2:55am UTC](https://discourse.processing.org/t/this-is-the-code-that-i-have-written-so-far-when-the-mouse-is-clicked-objects-will-appear-but-i-want-the-program-structured-in-which-if-the-mouse-is-pressed-again-on-an-object-the-object-will-delete/35348/1 "2022-02-21T02:55:48Z")

</div>

public class circle {  
float x, y;  
int circleShape;

public circle(float x, float y) {  
this.x = x;  
this.y = y;  
circleShape = floor(random(3));  
}

public void drawcircle() {  
if (circleShape == 0) {  
circle1();}

}

private void circle1() {  
fill(random(1000), random(1000), random(1000));  
stroke(200);  
strokeWeight(3);  
circle(x+25, y+25, 40);  
}

}

ArrayList circleList = new ArrayList();

boolean g = false;

void setup(){  
size(1000, 1000);  
}

void draw() {  
background(0);  
for (int i = 0; i \< circleList.size(); i++) {  
circleList.get(i).drawcircle();

}

}

void mousePressed() {  
circleList. add(new circle(mouseX, mouseY));  
}

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [February 21, 2022, 6:18am UTC](https://discourse.processing.org/t/this-is-the-code-that-i-have-written-so-far-when-the-mouse-is-clicked-objects-will-appear-but-i-want-the-program-structured-in-which-if-the-mouse-is-pressed-again-on-an-object-the-object-will-delete/35348/2 "2022-02-21T06:18:30Z")

</div>

> [@erijgeirg](#):
>
> for (int i = 0; i \< circleList.size(); i++) {  
> circleList.

Use a similar for loop in mousePressed and use dist() command to see if the mouse is in the circle

If yes, set a variable dead to true inside the class  
When it’s true don’t display the circle

Remove from array

Besides, it’s nice to have shorter titles for your posts, yours is a bit too long
