class ClickBox { int x, y, sizex, sizey; String text; ClickBox(int a, int b, String c) { this.x = a; this.y = b; this.sizex = 100; this.sizey = 40; this.text = c; } void showUp() { if (this.isMouseOver()) fill(255, 0, 0); else fill(0, 255, 0); rect(this.x, this.y, this.sizex, this.sizey); fill(0); text(this.text, this.x + this.sizex/2 - textWidth(this.text)/2, this.y + 15); } boolean isMouseOver() { return mouseX >= this.x && mouseX <= this.x + this.sizex && mouseY >= this.y && mouseY <= this.y + this.sizey; } } ClickBox rButton = new ClickBox(0, 0, "top?"); ClickBox[] buttons = new ClickBox[5]; void setup() { size(500, 500); for (int i = 0; i < buttons.length; i++) { buttons[i] = new ClickBox(100 * i, 200, "Button " + i); } } void draw() { background(0); rButton.showUp(); for (int i=0; i < buttons.length; i++) buttons[i].showUp(); } void mousePressed(){ for(int i=0; i < buttons.length; i++){ if(buttons[i].isMouseOver()){ if(i==0){ println("the first oen!"); }else if (i == 1){ println("the second one?"); } } } if(rButton.isMouseOver()){ println("some thign random " + random(100)); } }