#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# Code problem (GUI with 4 buttons)

edited March 2018

Hello ! I'm currently trying to start Processing for my school project. I must to do a GUI with 4 buttons. The goal it's to create a new geometric shape each time I push on a dufferent button. My problem is that 2 buttons doesn't work (right and up) but I don't know why .... Can anyone help me ?

Thank you,

Mat

``````int rectX1 , rectX2 , rectX3,rectX4 , rectY1 ,rectY2, rectY3,rectY4; // On va travailler avec des variables ainsi c'est plus simple de changer l'emplacement des boutons sans devoir rechanger tout le code
int ellipseX , ellipseY;
int rectSize = 50;
int ellipseSize = 100;
boolean rectOver1 = false;
boolean rectOver2 = false;
boolean rectOver3 = false;
boolean rectOver4 = false;
boolean circleOver = false;

void setup() //crée juste une fois au début
{
size(500,500);
background(0);
rectX1 = 350;
rectX2 = 400;
rectX3 = 350;
rectX4 = 300;
rectY1= 350;
rectY2 = 400;
rectY3 = 400;
rectY4 = 400 ;
ellipseX = 100;
ellipseY = 100;

stroke(0); //contour (blanc=255)
fill(255);//intérieur color
rect(rectX1 , rectY1,50,50); //DroiteGauche, HautBas , largeur , longueur  (Haut)
stroke(0,255,0);
fill(0,255,0);
rect(rectX2 , rectY2 , 50,50); //Droite
stroke(255,255,0);
fill(255,255,0);
rect(rectX3 , rectY3,50,50); // Bas
stroke(0,0,255);
fill(0,0,255);
rect(rectX4 , rectY4, 50,50); // Gauche
stroke(255,0,0);
fill(255,0,0);
ellipse(ellipseX , ellipseY ,100,100); //Tourner

}
void draw () //  Crée en continu
{

update(mouseX , mouseY) ;

}

void update(int x , int y) {
if (overRect(rectX1 , rectY1, rectSize , rectSize) )
{
rectOver1 = true;
rectOver2 = false;
rectOver3 = false;
rectOver4=false;
circleOver =false;
}
else {rectOver1 = rectOver2 =rectOver3 = rectOver4 = circleOver = false;}

if (overRect(rectX2 , rectY2, rectSize , rectSize))
{
rectOver1 = false;
rectOver2 = true;
rectOver3 = false;
rectOver4=false;
circleOver =false;
}
else {rectOver1 = rectOver2 =rectOver3 = rectOver4 = circleOver = false;}

if(overRect(rectX3 , rectY3 , rectSize , rectSize))
{
rectOver1 = false;
rectOver2 = false;
rectOver3 = true;
rectOver4=false;
circleOver =false;
}
else {rectOver1 = rectOver2 =rectOver3 = rectOver4 = circleOver = false ; }

if (overRect(rectX4 , rectY4 , rectSize, rectSize))
{
rectOver1 = false;
rectOver2 = false;
rectOver3 = false;
rectOver4=true;
circleOver =false;
}
}

boolean overRect(int x , int y , int width , int height ) {
if (mouseX >= x && mouseX <= x+width && mouseY >= y && mouseY <= y+height)
{
return true;
}
else {
return false;
}

}

void mousePressed() {
if(rectOver1)//haut
{
fill(255);
rect(300,300, 100,100);
}
if(rectOver2)//droite
{
fill(0,0,255);
ellipse(200,200,80,80);
}
if(rectOver3) //bas
{
rect(250,250,50,100);
}
if(rectOver4 )//gauche
{
ellipse(120, 50, 80,50);
}
else{ text("Error",50,50);
}
}
``````
Tagged: