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.

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) {


private void circle1() {
fill(random(1000), random(1000), random(1000));
circle(x+25, y+25, 40);


ArrayList circleList = new ArrayList();

boolean g = false;

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

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



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

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