Create a Menu


#1

I want to create a menu . when I run the program see first page with 3 box that are level 1 , level 2 and level 3
when I clicked on every box I can see the second page and boxes for each level and till here program works right.when I clicked on boxes for level 2 in second page only see the boxes for level one . what is problem.please help me
thanks
here is my code:

void mousePressed() {
// depending on the state choose mousePressed routine
// switch (state) {
// case stateWelcomeScreen:
if(stateWelcomeScreen){
mousePressedStateWelcomeScreen();
// break;
}
// case stateLevel:
else if(stateLevel){
mousePressedStatePlay();
//break;
}
//case stateAfterALevel:
// mousePressedStateAfterALevel();
else if(stateAfterALevel){

 stateWelcomeScreen= true;

// break;
}
}
void mousePressedStateWelcomeScreen() {
// Mouse pressed in state Welcome Screen / Main Screen.
// Evaluate three main buttons.
if (rectButtonBoard1.overRect()) {
// currentLevel = chooseLevel1;
chooseLevel1 = true;
chooseLevel2 = false;
chooseLevel3 = false;
// state = stateLevel;
stateLevel=true;
stateWelcomeScreen= false;
}
else if (rectButtonBoard2.overRect()) {
//currentLevel = chooseLevel2;
chooseLevel2 = true;
chooseLevel1 = false;
chooseLevel3 = false;
// state = stateLevel;
stateLevel=true;
stateWelcomeScreen= false;
}
else if (rectButtonBoard3.overRect()) {
// currentLevel = chooseLevel3;
chooseLevel3 = true;
chooseLevel2 = false;
chooseLevel1 = false;
// state = stateLevel;
stateLevel=true;
stateWelcomeScreen= false;
}

}
//

void mousePressedStatePlay() {

if (rectButtonBoard11.overRect()) {
// currentLevel1 = chooseLevel11;
chooseLevel11 = true;
stateAfterALevel = true;
stateLevel = false;

chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}

else if (rectButtonBoard12.overRect()) {
// currentLevel1 = chooseLevel12;
chooseLevel12 = true;
stateAfterALevel = true;
stateLevel = false;

chooseLevel11 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard13.overRect()) {
// currentLevel1 = chooseLevel13;
chooseLevel13 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel12 = false;
chooseLevel11 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard14.overRect()) {
// currentLevel1 = chooseLevel14;
chooseLevel14 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel11 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}

else if (rectButtonBoard21.overRect()) {
// currentLevel1 = chooseLevel21;
chooseLevel21 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard22.overRect()) {
// currentLevel1 = chooseLevel22;
chooseLevel22 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard23.overRect()) {
//currentLevel1 = chooseLevel23;
chooseLevel23 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard24.overRect()) {
//currentLevel1 = chooseLevel24;
chooseLevel24 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard25.overRect()) {
// currentLevel1 = chooseLevel25;
chooseLevel25 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel23 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard26.overRect()) {
// currentLevel1 = chooseLevel26;
chooseLevel26 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel23 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard27.overRect()) {
// currentLevel1 = chooseLevel27;
chooseLevel27 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel23 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard28.overRect()) {
//currentLevel1 = chooseLevel28;
chooseLevel28 = true;
stateAfterALevel = true;
stateLevel = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel23 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;
}
else if (rectButtonBoard31.overRect()) {
//currentLevel1 = chooseLevel31;
chooseLevel31 = true;
stateAfterALevel = true;
stateLevel=false;
chooseLevel32 = false;
chooseLevel33 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
}
else if (rectButtonBoard32.overRect()) {
// currentLevel1 = chooseLevel32;
chooseLevel32 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel31 = false;
chooseLevel33 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;

}
else if (rectButtonBoard33.overRect()) {
// currentLevel1 = chooseLevel33;
chooseLevel33 = true;
stateAfterALevel = true;
stateLevel = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
}

else if (rectButtonBoard34.overRect()) {

 stateWelcomeScreen = true;

}
else if (rectButtonBoard35.overRect()) {

 stateWelcomeScreen = true;

}
else if (rectButtonBoard36.overRect()) {

 stateWelcomeScreen = true;

}
else if (rectButtonBoard37.overRect()) {

 stateWelcomeScreen = true;

}

}


#2

When I try to run your code, I get compiler errors because none of your variables are defined.

The best thing I can tell you to do is debug your code to figure out exactly which line is doing something different from what you expected it to do. Start out using println() statements, and if that doesn’t work, then use the debugger that comes with the Processing editor.

When you get it narrowed down to just a few lines, then post a MCVE and we’ll go from there. Good luck!


#3

excuse me I send only some of my code all of them are here:
boolean stateWelcomeScreen = true;
boolean stateLevel = false;
boolean stateAfterALevel = false;

boolean chooseLevel1 = false;
boolean chooseLevel2 = false;
boolean chooseLevel3 = false;

boolean chooseLevel11 = false;
boolean chooseLevel12 = false;
boolean chooseLevel13 = false;
boolean chooseLevel14 = false;

boolean chooseLevel21 = false;
boolean chooseLevel22 = false;
boolean chooseLevel23 = false;
boolean chooseLevel24 = false;
boolean chooseLevel25 = false;
boolean chooseLevel26 = false;
boolean chooseLevel27 = false;
boolean chooseLevel28 = false;

boolean chooseLevel31 = false;
boolean chooseLevel32 = false;
boolean chooseLevel33 = false;

// their names
final String [] chooseLevelName =
{
“LEVEL 1”,
“LEVEL 2”,
“LEVEL 3”,

};
final String [] chooseLevel1Name =
{
“LEVEL 1-1”,
“LEVEL 1-2”,
“LEVEL 1-3”,
“LEVEL 1-4”
};

final String [] chooseLevel11Name =
{
“LEVEL 1-1-1”,
“LEVEL 1-1-2”,
“LEVEL 1-1-3”

};

final String [] chooseLevel12Name =
{
“LEVEL 1-2-1”,
“LEVEL 1-2-2”

};

final String [] chooseLevel13Name =
{
“LEVEL 1-3-1”,
“LEVEL 1-3-2”,
“LEVEL 1-3-3”

};
final String [] chooseLevel14Name =
{
“LEVEL 1-4-1”,
“LEVEL 1-4-2”

};
final String [] chooseLevel2Name =
{
“LEVEL 2-1”,
“LEVEL 2-2”,
“LEVEL 2-3”,
“LEVEL 2-4”,
“LEVEL 2-5”,
“LEVEL 2-6”,
“LEVEL 2-7”,
“LEVEL 2-8”
};

final String [] chooseLevel3Name =
{
“LEVEL 3-1”,
“LEVEL 3-2”,
"LEVEL 3-3 " ,
“LEVEL 3-4”,
“LEVEL 3-5”,
“LEVEL 3-6”,
"LEVEL 3-7 "
};

final String [] chooseLevel21Name =
{
“LEVEL 2-1-1”,
“LEVEL 2-1-2”,
“LEVEL 2-1-3”,
“LEVEL 2-1-4”
};
final String [] chooseLevel22Name =
{
“LEVEL 2-2-1”,
“LEVEL 2-2-2”,
“LEVEL 2-2-3”,
“LEVEL 2-2-4”
};
final String [] chooseLevel23Name =
{
“LEVEL 2-3-1”,
“LEVEL 2-3-2”,
“LEVEL 2-3-3”
};

final String [] chooseLevel24Name =
{
“LEVEL 2-4-1”,
“LEVEL 2-4-2”,
“LEVEL 2-4-3”,
“LEVEL 2-4-4”
};
final String [] chooseLevel25Name =
{
“LEVEL 2-5-1”,
“LEVEL 2-5-2”,
“LEVEL 2-5-3”
};
final String [] chooseLevel26Name =
{
“LEVEL 2-6-1”,
“LEVEL 2-6-2”
};
final String [] chooseLevel27Name =
{
“LEVEL 2-7-1”,
“LEVEL 2-7-2”
};

final String [] chooseLevel28Name =
{
“LEVEL 2-8-1”,
“LEVEL 2-8-2”
};

final String [] chooseLevel31Name =
{
“LEVEL 3-1-1”,
“LEVEL 3-1-2”,
“LEVEL 3-1-3”,
“LEVEL 3-1-4”
};
final String [] chooseLevel32Name =
{
“LEVEL 3-2-1”,
“LEVEL 3-2-2”
};

final String [] chooseLevel33Name =
{
“LEVEL 3-3-1”,
“LEVEL 3-3-2”,
“LEVEL 3-3-3”,
“LEVEL 3-3-4”
};

// the initial Main Menu
int textXPos;
int learnPos;
//int textXPos = width/2-300;
int[] textYPos = {

230,
390,
550,
700

};

int[] textYPos1 = {
50,
210,
370,
530

};
int[] textYPos11 = {
50,
210,
370
};

int[] textYPos12 = {
50,
210
};
int[] textYPos13 = {
50,
210,
370
};

int[] textYPos14 = {
50,
210
};

int[] textYPos2 = {
50,
100,
150,
200,
250,
300,
350,
400
};
int[] textYPos21 = {
50,
210,
370,
530
};
int[] textYPos22 = {
50,
210,
370,
530
};
int[] textYPos23 = {
50,
210,
370
};

int[] textYPos24 = {
50,
210,
370,
530
};
int[] textYPos25 = {
50,
210,
370
};
int[] textYPos26 = {
50,
210
};
int[] textYPos27 = {
50,
210
};
int[] textYPos28 = {
50,
210
};

int[] textYPos3 = {
50,
100,
150,
200,
250,
300,
350,
};
int[] textYPos31 = {
50,
210,
370,
530
};
int[] textYPos32 = {
50,
210
};
int[] textYPos33 = {
50,
210,
370,
530
};

// rectangles as buttons for main menu
Rectangle rectButtonBoard1;
Rectangle rectButtonBoard2;
Rectangle rectButtonBoard3;
//Rectangle rectLearnmore;
//rectangles as buttons for LEVEL ONE SECOND menu ***
Rectangle rectButtonBoard11;
Rectangle rectButtonBoard12;
Rectangle rectButtonBoard13;
Rectangle rectButtonBoard14;

//rectangles as buttons for LEVEL ONE THIRD menu ***
Rectangle rectButtonBoard111;
Rectangle rectButtonBoard112;
Rectangle rectButtonBoard113;

Rectangle rectButtonBoard121;
Rectangle rectButtonBoard122;

Rectangle rectButtonBoard131;
Rectangle rectButtonBoard132;
Rectangle rectButtonBoard133;

Rectangle rectButtonBoard141;
Rectangle rectButtonBoard142;

//rectangles as buttons for LEVEL TWO SECOND menu ***
Rectangle rectButtonBoard21;
Rectangle rectButtonBoard22;
Rectangle rectButtonBoard23;
Rectangle rectButtonBoard24;
Rectangle rectButtonBoard25;
Rectangle rectButtonBoard26;
Rectangle rectButtonBoard27;
Rectangle rectButtonBoard28;

//rectangles as buttons for LEVEL TWO THIRD menu ***
Rectangle rectButtonBoard211;
Rectangle rectButtonBoard212;
Rectangle rectButtonBoard213;
Rectangle rectButtonBoard214;

Rectangle rectButtonBoard221;
Rectangle rectButtonBoard222;
Rectangle rectButtonBoard223;
Rectangle rectButtonBoard224;

Rectangle rectButtonBoard231;
Rectangle rectButtonBoard232;
Rectangle rectButtonBoard233;

Rectangle rectButtonBoard241;
Rectangle rectButtonBoard242;
Rectangle rectButtonBoard243;
Rectangle rectButtonBoard244;

Rectangle rectButtonBoard251;
Rectangle rectButtonBoard252;
Rectangle rectButtonBoard253;

Rectangle rectButtonBoard261;
Rectangle rectButtonBoard262;

Rectangle rectButtonBoard271;
Rectangle rectButtonBoard272;

Rectangle rectButtonBoard281;
Rectangle rectButtonBoard282;

//rectangles as buttons for LEVEL THREE SECOND menu ***
Rectangle rectButtonBoard31;
Rectangle rectButtonBoard32;
Rectangle rectButtonBoard33;
Rectangle rectButtonBoard34;
Rectangle rectButtonBoard35;
Rectangle rectButtonBoard36;
Rectangle rectButtonBoard37;

//rectangles as buttons for LEVEL THREE THIRD menu ***
Rectangle rectButtonBoard311;
Rectangle rectButtonBoard312;
Rectangle rectButtonBoard313;
Rectangle rectButtonBoard314;

Rectangle rectButtonBoard321;
Rectangle rectButtonBoard322;

Rectangle rectButtonBoard331;
Rectangle rectButtonBoard332;
Rectangle rectButtonBoard333;
Rectangle rectButtonBoard334;

void setup () {
size (1000, 1000 );
// define values for class Rectangle
// PFont font;
// font = loadFont(“Badr-48.vlw”);
//textFont(font);
textXPos = width/2-300;
//learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard1 = new Rectangle(textXPos, textYPos[0], 500, 145, chooseLevelName[0]);
rectButtonBoard2 = new Rectangle(textXPos, textYPos[1], 500, 145, chooseLevelName[1]);
rectButtonBoard3 = new Rectangle(textXPos, textYPos[2], 500, 145, chooseLevelName[2]);
//rectLearnmore = new Rectangle(learnPos, textYPos[3], 100, 25, chooseGameName[3], -1);
}

void draw () {
background(0);
// see tab States for handling the states
if( stateWelcomeScreen){
handleStateShowWelcomeScreen();
}

else if (stateLevel){
handleStatePlay();
}
else if( stateAfterALevel){
handleStateAfterALevel();
}

} // func 

void mousePressed() {
// depending on the state choose mousePressed routine
// switch (state) {
// case stateWelcomeScreen:
if(stateWelcomeScreen){
mousePressedStateWelcomeScreen();
// break;
}
// case stateLevel:
else if(stateLevel){
mousePressedStatePlay();
//break;
}
//case stateAfterALevel:
// mousePressedStateAfterALevel();
else if(stateAfterALevel){

 stateWelcomeScreen= true;

// break;
}
}
void mousePressedStateWelcomeScreen() {
// Mouse pressed in state Welcome Screen / Main Screen.
// Evaluate three main buttons.
if (rectButtonBoard1.overRect()) {
// currentLevel = chooseLevel1;
chooseLevel1 = true;
chooseLevel2 = false;
chooseLevel3 = false;
// state = stateLevel;
stateLevel=true;
stateWelcomeScreen= false;
}
else if (rectButtonBoard2.overRect()) {
//currentLevel = chooseLevel2;
chooseLevel2 = true;
chooseLevel1 = false;
chooseLevel3 = false;
// state = stateLevel;
stateLevel=true;
stateWelcomeScreen= false;
}
else if (rectButtonBoard3.overRect()) {
// currentLevel = chooseLevel3;
chooseLevel3 = true;
chooseLevel2 = false;
chooseLevel1 = false;
// state = stateLevel;
stateLevel=true;
stateWelcomeScreen= false;
}

}
//

void mousePressedStatePlay() {

if (rectButtonBoard11.overRect()) {
// currentLevel1 = chooseLevel11;
chooseLevel11 = true;
stateAfterALevel = true;
stateLevel = false;

chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}

else if (rectButtonBoard12.overRect()) {
// currentLevel1 = chooseLevel12;
chooseLevel12 = true;
stateAfterALevel = true;
stateLevel = false;

chooseLevel11 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard13.overRect()) {
// currentLevel1 = chooseLevel13;
chooseLevel13 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel12 = false;
chooseLevel11 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard14.overRect()) {
// currentLevel1 = chooseLevel14;
chooseLevel14 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel11 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}

else if (rectButtonBoard21.overRect()) {
// currentLevel1 = chooseLevel21;
chooseLevel21 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard22.overRect()) {
// currentLevel1 = chooseLevel22;
chooseLevel22 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard23.overRect()) {
//currentLevel1 = chooseLevel23;
chooseLevel23 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard24.overRect()) {
//currentLevel1 = chooseLevel24;
chooseLevel24 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard25.overRect()) {
// currentLevel1 = chooseLevel25;
chooseLevel25 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel23 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard26.overRect()) {
// currentLevel1 = chooseLevel26;
chooseLevel26 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel23 = false;
chooseLevel27 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard27.overRect()) {
// currentLevel1 = chooseLevel27;
chooseLevel27 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel23 = false;
chooseLevel28 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;

}
else if (rectButtonBoard28.overRect()) {
//currentLevel1 = chooseLevel28;
chooseLevel28 = true;
stateAfterALevel = true;
stateLevel = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel23 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel33 = false;
}
else if (rectButtonBoard31.overRect()) {
//currentLevel1 = chooseLevel31;
chooseLevel31 = true;
stateAfterALevel = true;
stateLevel=false;
chooseLevel32 = false;
chooseLevel33 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
}
else if (rectButtonBoard32.overRect()) {
// currentLevel1 = chooseLevel32;
chooseLevel32 = true;
stateAfterALevel = true;
stateLevel=false;

chooseLevel31 = false;
chooseLevel33 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;

}
else if (rectButtonBoard33.overRect()) {
// currentLevel1 = chooseLevel33;
chooseLevel33 = true;
stateAfterALevel = true;
stateLevel = false;
chooseLevel31 = false;
chooseLevel32 = false;
chooseLevel11 = false;
chooseLevel12 = false;
chooseLevel13 = false;
chooseLevel14 = false;
chooseLevel21 = false;
chooseLevel22 = false;
chooseLevel23 = false;
chooseLevel24 = false;
chooseLevel25 = false;
chooseLevel26 = false;
chooseLevel27 = false;
chooseLevel28 = false;
}

else if (rectButtonBoard34.overRect()) {

 stateWelcomeScreen = true;

}
else if (rectButtonBoard35.overRect()) {

 stateWelcomeScreen = true;

}
else if (rectButtonBoard36.overRect()) {

 stateWelcomeScreen = true;

}
else if (rectButtonBoard37.overRect()) {

 stateWelcomeScreen = true;

}

}
class Rectangle {
int x, y, w, h; // Pos & Size
String textRect=""; // shown in the button (if in use)
//String textStatusBar=""; // shown in the status bar (if mouse over)
int associatedLevelIcon = -1; // which icon / graphical symbol to show

// constructor
Rectangle( int _x, int _y,
int _w, int _h,
String _text

// int _associatedLevelIcon
) {
x=_x;
y=_y;
w=_w;
h=_h;
textRect=_text;
// textStatusBar=_textStatusBar;
// associatedLevelIcon = _associatedLevelIcon;
} // constructor
public void outputRect() {
drawRectText();
drawRect();
// showIconForLevel();
} // method
/*
void showIconForLevel() {
switch (associatedLevelIcon) {
case -1:
// none: do nothing
break;
case 0:
// tictactoeBoard(x+30, y+34);
break;
case 1:
// solitaireBoard(x+40, y+40);
break;
case 2:
// chessBoard(x+40, y+40);
break;
default:
// error
println ("Error 23 with Solitaire: "
+ “Wrong number of associatedLevelIcon. Tab MenuRectangle, associatedLevelIcon: "
+ associatedLevelIcon
+ " (counting from zero).” );
exit();
break;
} // switch
} // func
*/
void drawRect() {
noFillOrLightColorDependingOnMouseOver();
stroke(255);
rect(x, y, w, h);
// status bar
if (overRect()) {
fill(255);
textSize(17);
textAlign(LEFT);
// text(textStatusBar, 15, height-15);
}
} // method

void drawRectText() {
if (!textRect.equals("")) {
fill(255);
textSize(17);
textAlign(CENTER);
text(textRect, x, y+(h/2)-9, w, h);
}
} // method

boolean overRect() {
if (mouseX>x && mouseX<x+w &&
mouseY>y && mouseY<y+h)
{
return true;
}
else
{
return false;
} // if else
} // method
//
void noFillOrLightColorDependingOnMouseOver() {
// this method sets a light background color for
// the button when mouse is over it
if (overRect())
fill(2, 255, 2, 42);
else
noFill();
} // method
//
} // class
//

void handleStateShowWelcomeScreen() {
//
// shows the main menu with the main game buttons
//
// headline

fill(255);
textSize(32);
textAlign(CENTER);
// 1st level option
rectButtonBoard1.outputRect();
// 2nd level option
rectButtonBoard2.outputRect();
// 3rd level option
rectButtonBoard3.outputRect();
// learn more box
// rectLearnmore.outputRect();
//

}
//
void handleStatePlay() {
//
if(chooseLevel1){
handleLevel1();
}
else if (chooseLevel2){
handleLevel2();
}
else if(chooseLevel3){
handleLevel3();
}
else {
// do nothing
}
}

void handleStateAfterALevel() {
// After a game:
// Wait for mousePressed
// to go to the Welcome Screen again.
if (chooseLevel11) {
handleLevel11();
}
else if(chooseLevel12){
handleLevel12();
}
else if( chooseLevel13){
handleLevel13();
}
else if( chooseLevel14){
handleLevel14();
}
else if (chooseLevel21) {
handleLevel21();
}
else if( chooseLevel22){
handleLevel22();
}
else if( chooseLevel23){
handleLevel23();
}
else if( chooseLevel24){
handleLevel24();
}
else if( chooseLevel25){
handleLevel25();
}
else if( chooseLevel26){
handleLevel26();
}
else if( chooseLevel27){
handleLevel27();
}
else if( chooseLevel28){
handleLevel28();
}
else if( chooseLevel31){
handleLevel31();
}
else if( chooseLevel32){
handleLevel32();
}
else if( chooseLevel33){
handleLevel33();
}
else {
// do nothing
}
//
} // func

void handleLevel1() {

textXPos = width/2-300;
//learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard11 = new Rectangle(textXPos, textYPos1[0], 500, 145, chooseLevel1Name[0]);
rectButtonBoard12 = new Rectangle(textXPos, textYPos1[1], 500, 145, chooseLevel1Name[1]);
rectButtonBoard13 = new Rectangle(textXPos, textYPos1[2], 500, 145, chooseLevel1Name[2]);
rectButtonBoard14 = new Rectangle(textXPos, textYPos1[3], 500, 145, chooseLevel1Name[3]);
// rectLearnmore = new Rectangle(learnPos, textYPos[3], 100, 25, chooseLevelName[0], -1);

rectButtonBoard11.outputRect();
rectButtonBoard12.outputRect();
rectButtonBoard13.outputRect();
rectButtonBoard14.outputRect();
}

void handleLevel11() {

// textXPos = width/2-300;

// define objects of class Rectangle
rectButtonBoard111 = new Rectangle(textXPos, textYPos11[0], 500, 145, chooseLevel11Name[0]);
rectButtonBoard112 = new Rectangle(textXPos, textYPos11[1], 500, 145, chooseLevel11Name[1]);
rectButtonBoard113 = new Rectangle(textXPos, textYPos11[2], 500, 145, chooseLevel11Name[2]);

//
rectButtonBoard111.outputRect();
rectButtonBoard112.outputRect();
rectButtonBoard113.outputRect();
}

void handleLevel12() {

//textXPos = width/2-300;

// define objects of class Rectangle
rectButtonBoard121 = new Rectangle(textXPos, textYPos12[0], 500, 145, chooseLevel12Name[0]);
rectButtonBoard122 = new Rectangle(textXPos, textYPos12[1], 500, 145, chooseLevel12Name[1]);
// 1st game option
rectButtonBoard121.outputRect();
rectButtonBoard122.outputRect();
}
void handleLevel13() {

// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard131 = new Rectangle(textXPos, textYPos13[0], 500, 145, chooseLevel13Name[0]);
rectButtonBoard132 = new Rectangle(textXPos, textYPos13[1], 500, 145, chooseLevel13Name[1]);
rectButtonBoard133 = new Rectangle(textXPos, textYPos13[2], 500, 145, chooseLevel13Name[2]);

// 1st game option
rectButtonBoard131.outputRect();
rectButtonBoard132.outputRect();
rectButtonBoard133.outputRect();

}

void handleLevel14() {

// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard141 = new Rectangle(textXPos, textYPos14[0], 500, 145, chooseLevel14Name[0]);
rectButtonBoard142 = new Rectangle(textXPos, textYPos14[1], 500, 145, chooseLevel14Name[1]);

rectButtonBoard141.outputRect();
rectButtonBoard142.outputRect();
}

void handleLevel2() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
rectButtonBoard21 = new Rectangle(textXPos, textYPos2[0], 500, 50, chooseLevel2Name[0]);
rectButtonBoard22 = new Rectangle(textXPos, textYPos2[1], 500,50, chooseLevel2Name[1]);
rectButtonBoard23 = new Rectangle(textXPos, textYPos2[2], 500, 50, chooseLevel2Name[2]);
rectButtonBoard24 = new Rectangle(textXPos, textYPos2[3], 500, 50, chooseLevel2Name[3]);
rectButtonBoard25 = new Rectangle(textXPos, textYPos2[4], 500, 50, chooseLevel2Name[4]);
rectButtonBoard26 = new Rectangle(textXPos, textYPos2[5], 500, 50, chooseLevel2Name[5]);
rectButtonBoard27 = new Rectangle(textXPos, textYPos2[6], 500, 50, chooseLevel2Name[6]);
rectButtonBoard28 = new Rectangle(textXPos, textYPos2[7], 500, 50, chooseLevel2Name[7]);
// rectButtonBoard6 = new Rectangle(textXPos, textYPos2[2], 500, 145, chooseLevel2Name[2]);
// rectLearnmore = new Rectangle(learnPos, textYPos[3], 100, 25, chooseLevelName[0], -1);

rectButtonBoard21.outputRect();
rectButtonBoard22.outputRect();
rectButtonBoard23.outputRect();
rectButtonBoard24.outputRect();
rectButtonBoard25.outputRect();
rectButtonBoard26.outputRect();
rectButtonBoard27.outputRect();
rectButtonBoard28.outputRect();

}

void handleLevel3() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
rectButtonBoard31 = new Rectangle(textXPos, textYPos3[0], 500, 45, chooseLevel3Name[0]);
rectButtonBoard32 = new Rectangle(textXPos, textYPos3[1], 500, 45, chooseLevel3Name[1]);
rectButtonBoard33 = new Rectangle(textXPos, textYPos3[2], 500, 45, chooseLevel3Name[2]);
rectButtonBoard34 = new Rectangle(textXPos, textYPos3[3], 500, 45, chooseLevel3Name[3]);
rectButtonBoard35 = new Rectangle(textXPos, textYPos3[4], 500, 45, chooseLevel3Name[4]);
rectButtonBoard36 = new Rectangle(textXPos, textYPos3[5], 500, 45, chooseLevel3Name[5]);
rectButtonBoard37 = new Rectangle(textXPos, textYPos3[6], 500, 45, chooseLevel3Name[6]);
// rectLearnmore = new Rectangle(learnPos, textYPos[3], 100, 25, chooseLevelName[0], -1);
// 1st game option
rectButtonBoard31.outputRect();
rectButtonBoard32.outputRect();
rectButtonBoard33.outputRect();
rectButtonBoard34.outputRect();
rectButtonBoard35.outputRect();
rectButtonBoard36.outputRect();
rectButtonBoard37.outputRect();
}
//
void handleLevel21() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard211 = new Rectangle(textXPos, textYPos21[0], 500, 145, chooseLevel21Name[0]);
rectButtonBoard212 = new Rectangle(textXPos, textYPos21[1], 500, 145, chooseLevel21Name[1]);
rectButtonBoard213 = new Rectangle(textXPos, textYPos21[2], 500, 145, chooseLevel21Name[2]);
rectButtonBoard214 = new Rectangle(textXPos, textYPos21[3], 500, 145, chooseLevel21Name[3]);

// 1st game option
rectButtonBoard211.outputRect();
rectButtonBoard212.outputRect();
rectButtonBoard213.outputRect();
rectButtonBoard214.outputRect();
}

void handleLevel22() {
//textXPos = width/2-300;
//learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard221 = new Rectangle(textXPos, textYPos22[0], 500, 145, chooseLevel22Name[0]);
rectButtonBoard222 = new Rectangle(textXPos, textYPos22[1], 500, 145, chooseLevel22Name[1]);
rectButtonBoard223 = new Rectangle(textXPos, textYPos22[2], 500, 145, chooseLevel22Name[2]);
rectButtonBoard224 = new Rectangle(textXPos, textYPos22[3], 500, 145, chooseLevel22Name[3]);

// 1st game option
rectButtonBoard221.outputRect();
rectButtonBoard222.outputRect();
rectButtonBoard223.outputRect();
rectButtonBoard224.outputRect();
}

void handleLevel23() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard231 = new Rectangle(textXPos, textYPos23[0], 500, 145, chooseLevel23Name[0]);
rectButtonBoard232 = new Rectangle(textXPos, textYPos23[1], 500, 145, chooseLevel23Name[1]);
rectButtonBoard233 = new Rectangle(textXPos, textYPos23[2], 500, 145, chooseLevel23Name[2]);

// 1st game option
rectButtonBoard231.outputRect();
rectButtonBoard232.outputRect();
rectButtonBoard233.outputRect();

}
void handleLevel24() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard241 = new Rectangle(textXPos, textYPos24[0], 500, 145, chooseLevel24Name[0]);
rectButtonBoard242 = new Rectangle(textXPos, textYPos24[1], 500, 145, chooseLevel24Name[1]);
rectButtonBoard243 = new Rectangle(textXPos, textYPos24[2], 500, 145, chooseLevel24Name[2]);
rectButtonBoard244 = new Rectangle(textXPos, textYPos24[3], 500, 145, chooseLevel24Name[3]);

// 1st game option
rectButtonBoard241.outputRect();
rectButtonBoard242.outputRect();
rectButtonBoard243.outputRect();
rectButtonBoard244.outputRect();
}
void handleLevel25() {
//textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard251 = new Rectangle(textXPos, textYPos25[0], 500, 145, chooseLevel25Name[0]);
rectButtonBoard252 = new Rectangle(textXPos, textYPos25[1], 500, 145, chooseLevel25Name[1]);
rectButtonBoard253 = new Rectangle(textXPos, textYPos25[2], 500, 145, chooseLevel25Name[2]);

// 1st game option
rectButtonBoard251.outputRect();
rectButtonBoard252.outputRect();
rectButtonBoard253.outputRect();
}

void handleLevel26() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard261 = new Rectangle(textXPos, textYPos26[0], 500, 145, chooseLevel26Name[0]);
rectButtonBoard262 = new Rectangle(textXPos, textYPos26[1], 500, 145, chooseLevel26Name[1]);

// 1st game option
rectButtonBoard261.outputRect();
rectButtonBoard262.outputRect();
}

void handleLevel27() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard271 = new Rectangle(textXPos, textYPos27[0], 500, 145, chooseLevel27Name[0]);
rectButtonBoard272 = new Rectangle(textXPos, textYPos27[1], 500, 145, chooseLevel27Name[1]);

// 1st game option
rectButtonBoard271.outputRect();
rectButtonBoard272.outputRect();
}

void handleLevel28() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard281 = new Rectangle(textXPos, textYPos28[0], 500, 145, chooseLevel28Name[0]);
rectButtonBoard282 = new Rectangle(textXPos, textYPos28[1], 500, 145, chooseLevel28Name[1]);

// 1st game option
rectButtonBoard281.outputRect();
rectButtonBoard282.outputRect();
}
void handleLevel31() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard311 = new Rectangle(textXPos, textYPos31[0], 500, 145, chooseLevel31Name[0]);
rectButtonBoard312 = new Rectangle(textXPos, textYPos31[1], 500, 145, chooseLevel31Name[1]);
rectButtonBoard313 = new Rectangle(textXPos, textYPos31[2], 500, 145, chooseLevel31Name[2]);
rectButtonBoard314 = new Rectangle(textXPos, textYPos31[3], 500, 145, chooseLevel31Name[3]);

// 1st game option

rectButtonBoard311.outputRect();
rectButtonBoard312.outputRect();
rectButtonBoard313.outputRect();
rectButtonBoard314.outputRect();
}
void handleLevel32() {
//textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard321 = new Rectangle(textXPos, textYPos32[0], 500, 145, chooseLevel32Name[0]);
rectButtonBoard322 = new Rectangle(textXPos, textYPos32[1], 500, 145, chooseLevel32Name[1]);

// 1st game option
rectButtonBoard321.outputRect();
rectButtonBoard322.outputRect();
}
void handleLevel33() {
// textXPos = width/2-300;
// learnPos = textXPos+400;
// define objects of class Rectangle
rectButtonBoard331 = new Rectangle(textXPos, textYPos33[0], 500, 145, chooseLevel33Name[0]);
rectButtonBoard332 = new Rectangle(textXPos, textYPos33[1], 500, 145, chooseLevel33Name[1]);
rectButtonBoard333 = new Rectangle(textXPos, textYPos33[2], 500, 145, chooseLevel33Name[2]);
rectButtonBoard334 = new Rectangle(textXPos, textYPos33[3], 500, 145, chooseLevel33Name[3]);

// 1st game option
rectButtonBoard331.outputRect();
rectButtonBoard332.outputRect();
rectButtonBoard333.outputRect();
rectButtonBoard334.outputRect();
}


#4

Sorry, but that is way too much code to debug for you. Like I said before, you need to debug your code to narrow the problem down to a MCVE, and we’ll go from there. Good luck.


#5

Hi Thanks for your attention.i write codes in simple Program.when I click on level 1 every thing is ok.but click on level 2 next page is right and see level2-1 but in second click see level 1-1-1 expect level 2-1-1 and this is wrong.i can’t understand where is the problem.
grateful
my codes:
boolean stateWelcomeScreen = true;
boolean stateLevel = false;
boolean stateAfterALevel = false;
boolean chooseLevel1 = false;
boolean chooseLevel2 = false;
boolean chooseLevel11 = false;
boolean chooseLevel21 = false;

// their names
final String [] chooseLevelName =
{
“LEVEL 1”,
“LEVEL 2”,
};
final String [] chooseLevel1Name =
{
“LEVEL 1-1”
};
final String [] chooseLevel11Name =
{
“LEVEL 1-1-1”
};
final String [] chooseLevel2Name =
{
“LEVEL 2-1”
};
final String [] chooseLevel21Name =
{
“LEVEL 2-1-1”
};

// the initial Main Menu
int textXPos;
int learnPos;
int[] textYPos = {

230,
390

};
int[] textYPos1 = {
50
};
int[] textYPos11 = {
50
};
int[] textYPos2 = {
50
};
int[] textYPos21 = {
50
};
// rectangles as buttons for main menu
Rectangle rectButtonBoard1;
Rectangle rectButtonBoard2;

//rectangles as buttons for LEVEL ONE SECOND menu ***
Rectangle rectButtonBoard11;
Rectangle rectButtonBoard111;
Rectangle rectButtonBoard21;
Rectangle rectButtonBoard211;
void setup () {
size (1000, 1000 );
// define values for class Rectangle
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard1 = new Rectangle(textXPos, textYPos[0], 500, 145, chooseLevelName[0]);
rectButtonBoard2 = new Rectangle(textXPos, textYPos[1], 500, 145, chooseLevelName[1]);
}

void draw () {
background(0);
// see tab States for handling the states
if( stateWelcomeScreen){
handleStateShowWelcomeScreen();
}

else if (stateLevel){
handleStatePlay();
}
else if( stateAfterALevel){
handleStateAfterALevel();
}
} // func

class Rectangle {

int x, y, w, h; // Pos & Size
String textRect=""; // shown in the button (if in use)
//String textStatusBar=""; // shown in the status bar (if mouse over)
int associatedLevelIcon = -1; // which icon / graphical symbol to show

// constructor
Rectangle( int _x, int _y,
int _w, int _h,
String _text

// int _associatedLevelIcon
) {
x=_x;
y=_y;
w=_w;
h=_h;
textRect=_text;
// textStatusBar=_textStatusBar;
// associatedLevelIcon = _associatedLevelIcon;
} // constructor
public void outputRect() {
drawRectText();
drawRect();
// showIconForLevel();
} // method
/*
void showIconForLevel() {
switch (associatedLevelIcon) {
case -1:
// none: do nothing
break;
case 0:
// tictactoeBoard(x+30, y+34);
break;
case 1:
// solitaireBoard(x+40, y+40);
break;
case 2:
// chessBoard(x+40, y+40);
break;
default:
// error
println ("Error 23 with Solitaire: "
+ “Wrong number of associatedLevelIcon. Tab MenuRectangle, associatedLevelIcon: "
+ associatedLevelIcon
+ " (counting from zero).” );
exit();
break;
} // switch
} // func
*/
void drawRect() {
noFillOrLightColorDependingOnMouseOver();
stroke(255);
rect(x, y, w, h);
// status bar
if (overRect()) {
fill(255);
textSize(17);
textAlign(LEFT);
// text(textStatusBar, 15, height-15);
}
} // method

void drawRectText() {
if (!textRect.equals("")) {
fill(255);
textSize(17);
textAlign(CENTER);
text(textRect, x, y+(h/2)-9, w, h);
}
} // method

boolean overRect() {
if (mouseX>x && mouseX<x+w &&
mouseY>y && mouseY<y+h)
{
return true;
}
else
{
return false;
} // if else
} // method
//
void noFillOrLightColorDependingOnMouseOver() {
// this method sets a light background color for
// the button when mouse is over it
if (overRect())
fill(2, 255, 2, 42);
else
noFill();
} // method
//
} // class
//

void mousePressed() {
// depending on the state choose mousePressed routine
// case stateWelcomeScreen:
if(stateWelcomeScreen){
mousePressedStateWelcomeScreen();
}
// case stateLevel:
else if(stateLevel){
mousePressedStatePlay();
}
else if(stateAfterALevel){
stateWelcomeScreen= true;
}
}
void mousePressedStateWelcomeScreen() {
// Mouse pressed in state Welcome Screen / Main Screen.
// Evaluate three main buttons.
if (rectButtonBoard1.overRect()) {
chooseLevel1 = true;
chooseLevel2 = false;

// state = stateLevel;
stateLevel=true;
stateWelcomeScreen= false;
}
else if (rectButtonBoard2.overRect()) {
chooseLevel2 = true;
chooseLevel1 = false;

// state = stateLevel;
stateLevel=true;
stateWelcomeScreen= false;
}

}
//
void mousePressedStatePlay() {

if (rectButtonBoard11.overRect()) {

chooseLevel11 = true;
stateAfterALevel = true;
stateLevel    = false;
chooseLevel21 = false;

}
else if (rectButtonBoard21.overRect()) {

chooseLevel21 = true;
stateAfterALevel = true;
stateLevel    = false;
chooseLevel11 = false;

}
}

void handleStateShowWelcomeScreen() {

fill(255);
textSize(32);
textAlign(CENTER);
// 1st level option
rectButtonBoard1.outputRect();
// 2nd level option
rectButtonBoard2.outputRect();
}
void handleStatePlay() {
//
if(chooseLevel1){
handleLevel1();
}
else if (chooseLevel2){
handleLevel2();
}
}
void handleStateAfterALevel() {

if (chooseLevel11) {
handleLevel11();
}
else if(chooseLevel21){
handleLevel21();
}
}
void handleLevel1() {

textXPos = width/2-300;

// define objects of class Rectangle
rectButtonBoard11 = new Rectangle(textXPos, textYPos1[0], 500, 145, chooseLevel1Name[0]);
rectButtonBoard11.outputRect();
}
void handleLevel11() {

textXPos = width/2-300;

// define objects of class Rectangle
rectButtonBoard111 = new Rectangle(textXPos, textYPos11[0], 500, 145, chooseLevel11Name[0]);
rectButtonBoard111.outputRect();
}
void handleLevel2() {
textXPos = width/2-300;

rectButtonBoard21 = new Rectangle(textXPos, textYPos2[0], 500, 50, chooseLevel2Name[0]);
rectButtonBoard21.outputRect();
}
void handleLevel21() {
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard211 = new Rectangle(textXPos, textYPos21[0], 500, 145, chooseLevel21Name[0]);
rectButtonBoard211.outputRect();
}


#6

Which line of code is behaving differently from what you expected it to do?


#7

}
//
void mousePressedStatePlay() {

if (rectButtonBoard11.overRect()) {

chooseLevel11 = true;
stateAfterALevel = true;
stateLevel = false;
chooseLevel21 = false;
}
else if (rectButtonBoard21.overRect()) {

chooseLevel21 = true;
stateAfterALevel = true;doesn’t
stateLevel = false;
chooseLevel11 = false;
}
}


#8

when I click on level 2-1 box ( this box is rectButtonBoard21.overRect()) ) and must be chooseLevel21 = true; but don’t do that and run rectButtonBoard11.overRect())


#9

I think problem is for mouseclick , which way else can check mouse click in my program


#10

when I click on level 2 box then I see level 2-1 but infact program consider level 1-1 Dimensions and think level 1-1 is show so when click on level2-1 box , I see level 1-1-1
but I don’t know why do that?


#11

// rectangles as buttons for main menu
Rectangle rectButtonBoard1; // show level 1 box
Rectangle rectButtonBoard2; // show level 2 box

//rectangles as buttons for LEVEL ONE SECOND menu ***
Rectangle rectButtonBoard11; // show level 11 box
Rectangle rectButtonBoard111;// show level 111 box
Rectangle rectButtonBoard21;// show level 21 box
Rectangle rectButtonBoard211;// show level 211 box


#12

another problem is that when first time run the program and first click on level 2 and next click on level 2-1 , processing has error on this line if (rectButtonBoard11.overRect()) {
nullpointerexception


#13

when I change the y position of level 1-1 ( int[] textYPos1 = {
500
};
, program work right but I can’t understand which way can solve the problem that in last y position works
that is new codes:
boolean stateWelcomeScreen = true;
boolean stateLevel = false;
boolean stateAfterALevel = false;
boolean chooseLevel1 = false;
boolean chooseLevel2 = false;
boolean chooseLevel11 = false;
boolean chooseLevel21 = false;

// their names
final String [] chooseLevelName =
{
“LEVEL 1”,
“LEVEL 2”,
};
final String [] chooseLevel1Name =
{
“LEVEL 1-1”
};
final String [] chooseLevel11Name =
{
“LEVEL 1-1-1”
};
final String [] chooseLevel2Name =
{
“LEVEL 2-1”
};
final String [] chooseLevel21Name =
{
“LEVEL 2-1-1”
};

// the initial Main Menu
int textXPos;
int learnPos;
int[] textYPos = {

230,
390

};
int[] textYPos1 = {
500
};
int[] textYPos11 = {
50
};
int[] textYPos2 = {
50
};
int[] textYPos21 = {
50
};
// rectangles as buttons for main menu
Rectangle rectButtonBoard1;
Rectangle rectButtonBoard2;

//rectangles as buttons for LEVEL ONE SECOND menu ***
Rectangle rectButtonBoard11;
Rectangle rectButtonBoard111;
Rectangle rectButtonBoard21;
Rectangle rectButtonBoard211;
void setup () {
size (1000, 1000 );
// define values for class Rectangle
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard1 = new Rectangle(textXPos, textYPos[0], 500, 145, chooseLevelName[0]);
rectButtonBoard2 = new Rectangle(textXPos, textYPos[1], 500, 145, chooseLevelName[1]);
}

void draw () {
background(0);
// see tab States for handling the states

if( stateWelcomeScreen){
handleStateShowWelcomeScreen();
}

else if (stateLevel){
handleStatePlay();
}
else if( stateAfterALevel){
handleStateAfterALevel();
}
} // func

class Rectangle {

int x, y, w, h; // Pos & Size
String textRect=""; // shown in the button (if in use)
//String textStatusBar=""; // shown in the status bar (if mouse over)
int associatedLevelIcon = -1; // which icon / graphical symbol to show

// constructor
Rectangle( int _x, int _y,
int _w, int _h,
String _text

// int _associatedLevelIcon
) {
x=_x;
y=_y;
w=_w;
h=_h;
textRect=_text;
// textStatusBar=_textStatusBar;
// associatedLevelIcon = _associatedLevelIcon;
} // constructor
public void outputRect() {
drawRectText();
drawRect();
// showIconForLevel();
} // method
/*
void showIconForLevel() {
switch (associatedLevelIcon) {
case -1:
// none: do nothing
break;
case 0:
// tictactoeBoard(x+30, y+34);
break;
case 1:
// solitaireBoard(x+40, y+40);
break;
case 2:
// chessBoard(x+40, y+40);
break;
default:
// error
println ("Error 23 with Solitaire: "
+ “Wrong number of associatedLevelIcon. Tab MenuRectangle, associatedLevelIcon: "
+ associatedLevelIcon
+ " (counting from zero).” );
exit();
break;
} // switch
} // func
*/
void drawRect() {
noFillOrLightColorDependingOnMouseOver();
stroke(255);
rect(x, y, w, h);
// status bar
if (overRect()) {
fill(255);
textSize(17);
textAlign(LEFT);
// text(textStatusBar, 15, height-15);
}
} // method

void drawRectText() {
if (!textRect.equals("")) {
fill(255);
textSize(17);
textAlign(CENTER);
text(textRect, x, y+(h/2)-9, w, h);
}
} // method

boolean overRect() {
if (mouseX>x && mouseX<x+w &&
mouseY>y && mouseY<y+h)
{
return true;
}
else
{
return false;
} // if else
} // method
//
void noFillOrLightColorDependingOnMouseOver() {
// this method sets a light background color for
// the button when mouse is over it
if (overRect())
fill(2, 255, 2, 42);
else
noFill();
} // method
//
} // class
//

void mousePressed() {
// depending on the state choose mousePressed routine
// case stateWelcomeScreen:

if(stateWelcomeScreen){
mousePressedStateWelcomeScreen();
}
// case stateLevel:
else if(stateLevel){
mousePressedStatePlay();
}
else if(stateAfterALevel){
stateWelcomeScreen= true;
}
}
void mousePressedStateWelcomeScreen() {
// Mouse pressed in state Welcome Screen / Main Screen.
// Evaluate three main buttons.

if (rectButtonBoard1.overRect()) {
chooseLevel1 = true;
chooseLevel2 = false;

// state = stateLevel;
// stateLevel=true;
// stateWelcomeScreen= false;
}
else if (rectButtonBoard2.overRect()) {
chooseLevel2 = true;
chooseLevel1 = false;

// state = stateLevel;
// stateLevel=true;
// stateWelcomeScreen= false;
}
if(chooseLevel1 || chooseLevel2)
{
stateLevel = true;
stateWelcomeScreen = false;
}

}
//
void mousePressedStatePlay() {
//<>//
if (rectButtonBoard11.overRect()) {

chooseLevel11 = true;

// stateAfterALevel = true;
// stateLevel = false;
chooseLevel21 = false;
}
else if (rectButtonBoard21.overRect()) {

chooseLevel21 = true;
// stateAfterALevel = true;
// stateLevel = false;
chooseLevel11 = false;
}
if(chooseLevel11 || chooseLevel21)
{
stateLevel = false;
stateAfterALevel = true;
}
}

void handleStateShowWelcomeScreen() {

fill(255);
textSize(32);
textAlign(CENTER);
// 1st level option
rectButtonBoard1.outputRect();
// 2nd level option
rectButtonBoard2.outputRect();
}
void handleStatePlay() {
//
if(chooseLevel1){
handleLevel1();
}
else if (chooseLevel2){
handleLevel2();
}
}
void handleStateAfterALevel() {

if (chooseLevel11) {
handleLevel11();
}
else if(chooseLevel21){
handleLevel21();
}
}
void handleLevel1() {
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard11 = new Rectangle(textXPos, textYPos1[0], 500, 145, chooseLevel1Name[0]);
rectButtonBoard11.outputRect();
}
void handleLevel11() {
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard111 = new Rectangle(textXPos, textYPos11[0], 500, 145, chooseLevel11Name[0]);
rectButtonBoard111.outputRect();
}
void handleLevel2() {
textXPos = width/2-300;

rectButtonBoard21 = new Rectangle(textXPos, textYPos2[0], 500, 50, chooseLevel2Name[0]);
rectButtonBoard21.outputRect();
}
void handleLevel21() {
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard211 = new Rectangle(textXPos, textYPos21[0], 500, 145, chooseLevel21Name[0]);
rectButtonBoard211.outputRect();
}


#14

in fact problem is that when click on first box in next page only see one box but in fact program see all of the boxes and click on position of each ones show boxes for that position. do you understand What do I mean?
excuse me for my poor English


#15

hi
With the help of my best friend fixed it.we show each box in different page add this thing
boolean stateLevel1 = false;
boolean stateLevel2 = false;
best wishes


#16

You might consider refactoring your code so different menus are in different classes or something. Right now your code is very hard to read, which is probably not making your life very easy!


#17

that is my codes:
boolean stateWelcomeScreen = true;
boolean stateLevel1 = false;
boolean stateLevel2 = false;
boolean stateAfterALevel = false;

boolean chooseLevel1 = false;
boolean chooseLevel2 = false;
boolean chooseLevel11 = false;
boolean chooseLevel21 = false;

// their names
final String [] chooseLevelName =
{
“LEVEL 1”,
“LEVEL 2”,
};
final String [] chooseLevel1Name =
{
“LEVEL 1-1”
};
final String [] chooseLevel11Name =
{
“LEVEL 1-1-1”
};
final String [] chooseLevel2Name =
{
“LEVEL 2-1”
};
final String [] chooseLevel21Name =
{
“LEVEL 2-1-1”
};

// the initial Main Menu
int textXPos;
int learnPos;
int[] textYPos = {

230,
390

};
int[] textYPos1 = {
50
};
int[] textYPos11 = {
50
};
int[] textYPos2 = {
50
};
int[] textYPos21 = {
50
};
// rectangles as buttons for main menu
Rectangle rectButtonBoard1;
Rectangle rectButtonBoard2;

//rectangles as buttons for LEVEL ONE SECOND menu ***
Rectangle rectButtonBoard11;
Rectangle rectButtonBoard111;
Rectangle rectButtonBoard21;
Rectangle rectButtonBoard211;
void setup () {
size (1000, 1000 );
// define values for class Rectangle
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard1 = new Rectangle(textXPos, textYPos[0], 500, 145, chooseLevelName[0]);
rectButtonBoard2 = new Rectangle(textXPos, textYPos[1], 500, 145, chooseLevelName[1]);
}

void draw () {
background(0);
// see tab States for handling the states

if( stateWelcomeScreen){
handleStateShowWelcomeScreen();
}

else if (stateLevel1 ){
handleStatePlay1();
}
else if (stateLevel2 ){
handleStatePlay2();
}
else if( stateAfterALevel){
handleStateAfterALevel();
}
} // func

class Rectangle {
int x, y, w, h; // Pos & Size
String textRect=""; // shown in the button (if in use)
//String textStatusBar=""; // shown in the status bar (if mouse over)
int associatedLevelIcon = -1; // which icon / graphical symbol to show

// constructor
Rectangle( int _x, int _y,
int _w, int _h,
String _text

// int _associatedLevelIcon
) {
x=_x;
y=_y;
w=_w;
h=_h;
textRect=_text;
// textStatusBar=_textStatusBar;
// associatedLevelIcon = _associatedLevelIcon;
} // constructor
public void outputRect() {
drawRectText();
drawRect();
// showIconForLevel();
} // method
/*
void showIconForLevel() {
switch (associatedLevelIcon) {
case -1:
// none: do nothing
break;
case 0:
// tictactoeBoard(x+30, y+34);
break;
case 1:
// solitaireBoard(x+40, y+40);
break;
case 2:
// chessBoard(x+40, y+40);
break;
default:
// error
println ("Error 23 with Solitaire: "
+ “Wrong number of associatedLevelIcon. Tab MenuRectangle, associatedLevelIcon: "
+ associatedLevelIcon
+ " (counting from zero).” );
exit();
break;
} // switch
} // func
*/
void drawRect() {
noFillOrLightColorDependingOnMouseOver();
stroke(255);
rect(x, y, w, h);
// status bar
if (overRect()) {
fill(255);
textSize(17);
textAlign(LEFT);
// text(textStatusBar, 15, height-15);
}
} // method

void drawRectText() {
if (!textRect.equals("")) {
fill(255);
textSize(17);
textAlign(CENTER);
text(textRect, x, y+(h/2)-9, w, h);
}
} // method

boolean overRect() {
if (mouseX>x && mouseX<x+w &&
mouseY>y && mouseY<y+h)
{
return true;
}
else
{
return false;
} // if else
} // method
//
void noFillOrLightColorDependingOnMouseOver() {
// this method sets a light background color for
// the button when mouse is over it
if (overRect())
fill(2, 255, 2, 42);
else
noFill();
} // method
//
} // class
//
void mousePressed() {
// depending on the state choose mousePressed routine
// case stateWelcomeScreen:

if(stateWelcomeScreen){
mousePressedStateWelcomeScreen();
}
// case stateLevel:
else if(stateLevel1 ){
mousePressedStatePlay1();
}
else if(stateLevel2 ){
mousePressedStatePlay2();
}
else if(stateAfterALevel){
stateWelcomeScreen= true;
}
}
void mousePressedStateWelcomeScreen() {
// Mouse pressed in state Welcome Screen / Main Screen.
// Evaluate three main buttons.

if (rectButtonBoard1.overRect()) {
chooseLevel1 = true;
chooseLevel2 = false;

// state = stateLevel;
stateLevel1=true;
stateLevel2=false;
stateWelcomeScreen= false;
}
else if (rectButtonBoard2.overRect()) {
chooseLevel2 = true;
chooseLevel1 = false;

// state = stateLevel;
stateLevel2=true;
stateLevel1=false;
stateWelcomeScreen= false;
}
else
{
}
/*
if(chooseLevel1 || chooseLevel2)
{
stateLevel = true;
stateWelcomeScreen = false;
}
*/
}
//
void mousePressedStatePlay1() {

if (rectButtonBoard11.overRect()) {

chooseLevel11 = true;

chooseLevel21 = false;
stateAfterALevel = true;
stateLevel1    = false;
stateLevel2    = false;

}
}
void mousePressedStatePlay2() {

if (rectButtonBoard21.overRect()) {

chooseLevel21 = true;
//stateAfterALevel = true;
// stateLevel = false;
chooseLevel11 = false;
stateAfterALevel = true;
stateLevel1 = false;
stateLevel2 = false;
}
else
{
}

}

void handleStateShowWelcomeScreen() {

fill(255);
textSize(32);
textAlign(CENTER);
// 1st level option
rectButtonBoard1.outputRect();
// 2nd level option
rectButtonBoard2.outputRect();
}
void handleStatePlay1() {
//
if(chooseLevel1){
handleLevel1();
}
}
void handleStatePlay2() {
//
if(chooseLevel2){
handleLevel2();
}

}
void handleStateAfterALevel() {

if (chooseLevel11 && chooseLevel1 ) {
handleLevel11();
}
else if(chooseLevel21 && chooseLevel2 ){
handleLevel21();
}
}
void handleLevel1() {
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard11 = new Rectangle(textXPos, textYPos1[0], 500, 145, chooseLevel1Name[0]);
rectButtonBoard11.outputRect();
}
void handleLevel11() {
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard111 = new Rectangle(textXPos, textYPos11[0], 500, 145, chooseLevel11Name[0]);
rectButtonBoard111.outputRect();
}
void handleLevel2() {
textXPos = width/2-300;

rectButtonBoard21 = new Rectangle(textXPos, textYPos2[0], 500, 50, chooseLevel2Name[0]);
rectButtonBoard21.outputRect();
}
void handleLevel21() {
textXPos = width/2-300;
// define objects of class Rectangle
rectButtonBoard211 = new Rectangle(textXPos, textYPos21[0], 500, 145, chooseLevel21Name[0]);
rectButtonBoard211.outputRect();
}