# Renderer Problems - Login System and Menu

**URL:** <https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331>\
**Category:** Coding Questions\
**Created:** [April 2, 2020, 10:00am UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331 "2020-04-02T10:00:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaysLoop](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@DaysLoop](https://discourse.processing.org/u/DaysLoop)\
**Post date:** [April 2, 2020, 10:00am UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/1 "2020-04-02T10:00:22Z")

</div>

Sorry, but I’m inexperienced in Processing.  
I have um little test code where one menu open after login accepted. The two functions work individually, but when I put them together I have this error “translate(), or this particular variation of it, is not available with this renderer.”

Thanks for your help.

My code is:

> Blockquote  
> //Bibliotecas  
> import static javax.swing.JOptionPane.\*;  
> import javax.swing.JPasswordField;

//Variaveis

int validar = 0;

final StringDict accounts = new StringDict( //Uma classe simples para usar uma String como uma pesquisa para um valor de String. As “chaves” da sequência estão associadas aos valores da sequência.  
new String {  
“baptiste”, “tanguy”, “alexis”  
},  
new String {  
“bap”, “guy”, “ex”  
}  
);

final JPasswordField pwd = new JPasswordField();

{  
println(accounts);  
}

//menu  
// states  
final int stateMenu = 0;  
final int stateMenu\_jogar = 1;  
final int definicoes\_gerais = 2;  
final int analise\_dados = 3;  
final int jogar\_normal = 4;  
final int jogar\_normal\_audio = 5;  
int state = stateMenu;  
//  
//

//------

void settings(){  
size(700,800);  
smooth();  
}

void setup(){  
textAlign(CENTER, CENTER);  
rectMode(CENTER);

fill(255);  
strokeWeight(2);  
//login();  
}

//------

void draw(){  
background(255, 204, 0);  
if (validar == 1){  
//println(“aqui”);  
menu();  
}  
else login();  
//login();  
//menu();  
//if (validar != 1){  
// login();  
//} else menu();

## //switch(validar){ // case 1: // menu(); // println(“menu”); // break; // case 0: // login(); // println(“login”); // break; //} }

//-----Login

void login(){  
if (frameCount == 1) surface.setVisible(false);

String user = askUser();

if (user == null) confirmQuit();  
else if (!“”.equals(user)) askPass(user);  
}

String askUser() { //tela pergunta utilizador  
String id = showInputDialog(“Please enter user:”); //dialogo inicial

if (id == null) //caso a resposta seja carregar na tecla cancelar  
showMessageDialog(null, “You’ve canceled login operation!”, “Alert”, ERROR\_MESSAGE);

```
else if ("".equals(id)) //caso a resposta seja sem colocar dados
  showMessageDialog(null, "Empty user input!", "Alert", ERROR_MESSAGE);
  
  else if (!accounts.hasKey(id = id.toLowerCase())) //caso a resposta seja a errada
  showMessageDialog(null, "UnKnown \"" + id + "\" user!" + (id = ""), "Alert", ERROR_MESSAGE);
  
  return id;

```

}

boolean askPass(String id){  
boolean isLogged = false;  
pwd.setText(“”);

int action = showConfirmDialog(null, pwd, “Now enter password:”, OK\_CANCEL\_OPTION);

if (action != OK\_OPTION){  
showMessageDialog(null, “Password input canceled!”, “Alert”, ERROR\_MESSAGE);

```
return false;

```

}

//String phrase = pwd.getText();  
String phrase = new String(pwd.getPassword());

if (“”.equals(phrase))  
showMessageDialog(null, “Empty password input!”, “Alert”, ERROR\_MESSAGE);

else if (accounts.get(id).equals(phrase)) { //password correta  
showMessageDialog(null, “Welcome "”+ id +“"!\nYou’re logged in!”, “Infor”, INFORMATION\_MESSAGE);

```
isLogged = true;
validar = 1;

```

}

else  
showMessageDialog(null, “Password "” + phrase + “" mismatch!”, “Alert!”, ERROR\_MESSAGE);

```
return isLogged;  

```

}

## void confirmQuit(){ if (showConfirmDialog(null, “Wanna quit then?”, “Exit”, OK\_CANCEL\_OPTION) == OK\_OPTION) exit(); }

## void menu(){ // the main routine. It handels the states. // runs again and again switch (state) { case stateMenu: showMenu(); break; case stateMenu\_jogar: handlestateMenu\_jogar(); break; case definicoes\_gerais: handledefinicoes\_gerais(); break; case analise\_dados: handleanalise\_dados(); break; case jogar\_normal: handlejogar\_normal(); break; case jogar\_normal\_audio: handlejogar\_normal\_audio(); break; default: println (“Unknown state (in draw) " + state + " ++++++++++++++++++++++”); exit(); break; } // switch // }//

// ----------------------------------------------------------------  
// keyboard functions

void keyPressed() {  
// keyboard. Also different depending on the state.  
switch (state) {  
case stateMenu:  
keyPressedForStateMenu();  
break;  
case stateMenu\_jogar:  
keyPressedForstateMenu\_jogar();  
break;  
case definicoes\_gerais:  
keyPressedFordefinicoes\_gerais();  
break;  
case analise\_dados:  
keyPressedForanalise\_dados();  
break;  
case jogar\_normal:  
keyPressedForjogar\_normal();  
break;  
case jogar\_normal\_audio:  
keyPressedForjogar\_normal\_audio();  
break;  
default:  
println (“Unknown state (in keypressed) "  
+ state  
+ " ++++++++++++++++++++++”);  
exit();  
break;  
} // switch  
//  
} // func  
void keyPressedForStateMenu() {  
//  
switch(key) {  
case ‘1’:  
state = stateMenu\_jogar;  
break;  
case ‘2’:  
state = definicoes\_gerais;  
break;  
case ‘3’:  
state = analise\_dados;  
break;  
case ‘4’:  
state = jogar\_normal;  
break;  
case ‘5’ :  
state = jogar\_normal\_audio;  
break;  
case ‘x’:  
case ‘X’:  
// quit  
exit();  
break;  
default:  
// do nothing  
break;  
}// switch  
//  
} // func  
void keyPressedForstateMenu\_jogar() {  
// any key is possible  
switch(key) {  
case ‘4’:  
state = jogar\_normal;  
break;  
case ‘5’ :  
state = jogar\_normal\_audio;  
break;  
case ‘x’:  
case ‘X’:  
state = stateMenu;  
break;  
default:  
state = stateMenu\_jogar;  
break;  
} // switch  
//  
} // func  
void keyPressedFordefinicoes\_gerais() {  
// any key is possible  
switch(key) {  
default:  
state = stateMenu;  
break;  
} // switch  
//  
} // func  
void keyPressedForanalise\_dados() {  
// any key is possible  
switch(key) {  
default:  
state = stateMenu;  
break;  
} // switch  
//  
} // func

void keyPressedForjogar\_normal() {  
// any key is possible  
switch(key) {  
default:  
state = jogar\_normal;  
break;  
} // switch  
//  
} // func

## void keyPressedForjogar\_normal\_audio() { // any key is possible switch(key) { default: state = jogar\_normal\_audio; break; } // switch // } // func

// ----------------------------------------------------------------  
// functions to show the menu and functions that are called from the menu.  
// They depend on the states and are called by draw().

void showMenu() {  
background(255, 204, 0);  
fill(0);  
textSize(32);  
text(" Jogo da Memória ", 150, 100, 3);  
textSize(14);  
text("Press 1 para Jogar ", 100, 200);  
text("Press 2 para Definições Gerais ", 100, 220);  
text(“Press 3 See Análise de Dados”, 100,240);  
//  
text("Press x para sair ", 100, 260);  
//  
} // func

void handlestateMenu\_jogar() {  
background(255, 204, 0);  
fill(0);  
textSize(32);  
text(" Escolhe jogo ", 150, 100, 3);  
textSize(14);  
text(“4 - Jogar jogo normal”, 100, 200);  
text(“5 - Jogar jogo audio”, 100, 300);  
text(“x - voltar ao menu”, 100, 400);  
//  
} // func  
//

void handledefinicoes\_gerais() {  
background(255, 204, 0);  
fill(0);  
textSize(32);  
text(" Ver definições gerais “, 150, 100, 3);  
textSize(14);  
text(”… some text ", 100, 200);  
//  
} // func

void handleanalise\_dados() {  
background(255, 204, 0);  
fill(0);  
textSize(32);  
text(" Ver analise\_dados “, 150, 100, 3);  
textSize(14);  
text(”… some text ", 100, 200);  
//  
} // func

void handlejogar\_normal() {  
background(255, 204, 0);  
//fill(0);  
//textSize(32);  
//text(" colocar jogos normais ", 150, 100, 3);  
//textSize(14);  
//text("jogo ", 100, 200);  
//  
} // func

void handlejogar\_normal\_audio() {  
background(255, 204, 0);  
fill(0);  
textSize(32);  
text(" colocar jogo normais e audio “, 150, 100, 3);  
textSize(14);  
text(” jogo ", 100, 200);  
//  
}

// ----------------------------------------------------------------  
//

---

<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:** [April 2, 2020, 10:14am UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/2 "2020-04-02T10:14:54Z")

</div>

translate is only possible in P3D

So change size() in setup ()

---

<div class="post-metadata">

**Author:** ![DaysLoop](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@DaysLoop](https://discourse.processing.org/u/DaysLoop)\
**Post date:** [April 2, 2020, 12:02pm UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/3 "2020-04-02T12:02:56Z")

</div>

thank’s Chrisir.

But the same problem. I think the problem is in the login () function which makes it impossible for the menu () functions to run.

---

<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:** [April 2, 2020, 1:05pm UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/4 "2020-04-02T13:05:27Z")

</div>

interesting

The window dissapears.

Otherwise it works, aqui and jdsh both show up.

**I think**

```auto

import static javax.swing.JOptionPane.*;
import javax.swing.JPasswordField;

```

is not compatible with processing.

We have to ask the gurus!

@GoToLoop

Chrisir

```auto

//Bibliotecas
import static javax.swing.JOptionPane.*;
import javax.swing.JPasswordField;

//Variaveis
int validar = 0;

//Uma classe simples para usar uma String como uma pesquisa para um valor de String. As “chaves” da sequência estão associadas aos valores da sequência.
final StringDict accounts = 
  new StringDict(
  new String [] {
  "baptiste", "tanguy", "alexis"
  }, 
  new String [] {
    "bap", "guy", "ex"
  }
  );

final JPasswordField pwd = new JPasswordField();

{
  println(accounts);
}

//menu
// states
final int stateMenu = 0;
final int stateMenu_jogar = 1;
final int definicoes_gerais = 2;
final int analise_dados = 3;
final int jogar_normal = 4;
final int jogar_normal_audio = 5;
int state = stateMenu;
//
//

//------

void setup() {
  size(700, 800);
  smooth();

  textAlign(CENTER, CENTER);
  rectMode(CENTER);

  fill(255);
  strokeWeight(2);
  //login();
}

//------

void draw() {
  background(255, 204, 0);

  if (validar == 1) {
    println("aqui");
    menu();
  } else {
    login();
  }

  //login();
  //menu();
  //if (validar != 1){
  // login();
  //} else menu();
  //switch(validar){
  // case 1:
  // menu();
  // println(“menu”);
  // break;
  // case 0:
  // login();
  // println(“login”);
  // break;
  //}
}

//-----Login

void login() {
  if (frameCount == 1) surface.setVisible(false);

  String user = askUser();

  if (user == null) 
    confirmQuit();
  else if (!"".equals(user))
    askPass(user);
}

String askUser() { //tela pergunta utilizador
  String id = showInputDialog("Please enter user:"); //dialogo inicial

  if (id == null) //caso a resposta seja carregar na tecla cancelar
    showMessageDialog(null, "You’ve canceled login operation!", "Alert", ERROR_MESSAGE);

  else if ("".equals(id)) //caso a resposta seja sem colocar dados
    showMessageDialog(null, "Empty user input!", "Alert", ERROR_MESSAGE);

  else if (!accounts.hasKey(id = id.toLowerCase())) //caso a resposta seja a errada
    showMessageDialog(null, "UnKnown \"" + id + "\" user!" + (id = ""), "Alert", ERROR_MESSAGE);

  return id;
}

boolean askPass(String id) {

  boolean isLogged = false;
  pwd.setText("");

  int action = showConfirmDialog(null, pwd, "Now enter password:", OK_CANCEL_OPTION);

  if (action != OK_OPTION) {
    showMessageDialog(null, "Password input canceled!", "Alert", ERROR_MESSAGE);

    return false;
  }

  //String phrase = pwd.getText();
  String phrase = new String(pwd.getPassword());

  if ("".equals(phrase)) {
    showMessageDialog(null, "Empty password input!", "Alert", ERROR_MESSAGE);
  } else if (accounts.get(id).equals(phrase)) { //password correta
    showMessageDialog(null, "Welcome "
      + id
      +
      "!\nYou’re logged in!", 
      "Infor", 
      INFORMATION_MESSAGE);

    isLogged = true;
    validar = 1; // validar = 1
  } else {
    showMessageDialog(null, 
      "Password " + phrase + " mismatch!", "Alert!", ERROR_MESSAGE);
  }

  return isLogged;
}

void confirmQuit() {
  if (showConfirmDialog(null, 
    "Wanna quit then?", "Exit", OK_CANCEL_OPTION) == OK_OPTION)
    exit();
}

void menu() {
  // the main routine. It handels the states.
  // runs again and again
  switch (state) {
  case stateMenu:
    showMenu();
    break;
  case stateMenu_jogar:
    handlestateMenu_jogar();
    break;
  case definicoes_gerais:
    handledefinicoes_gerais();
    break;
  case analise_dados:
    handleanalise_dados();
    break;
  case jogar_normal:
    handlejogar_normal();
    break;
  case jogar_normal_audio:
    handlejogar_normal_audio();
    break;
  default:
    println ("Unknown state (in draw) "
      + state
      + "++++++++++++++++++++++");
    exit();
    break;
  } // switch
  //
}//

// ----------------------------------------------------------------
// keyboard functions

void keyPressed() {
  // keyboard. Also different depending on the state.
  switch (state) {
  case stateMenu:
    keyPressedForStateMenu();
    break;
  case stateMenu_jogar:
    keyPressedForstateMenu_jogar();
    break;
  case definicoes_gerais:
    keyPressedFordefinicoes_gerais();
    break;
  case analise_dados:
    keyPressedForanalise_dados();
    break;
  case jogar_normal:
    keyPressedForjogar_normal();
    break;
  case jogar_normal_audio:
    keyPressedForjogar_normal_audio();
    break;
  default:
    println ("Unknown state (in keypressed) "
      + state
      + " ++++++++++++++++++++++");
    exit();
    break;
  } // switch
  //
} // func

void keyPressedForStateMenu() {
  //
  switch(key) {
  case '1':
    state = stateMenu_jogar;
    break;
  case '2':
    state = definicoes_gerais;
    break;
  case '3':
    state = analise_dados;
    break;
  case '4':
    state = jogar_normal;
    break;
  case '5' :
    state = jogar_normal_audio;
    break;
  case 'x':
  case 'X':
    // quit
    exit();
    break;
  default:
    // do nothing
    break;
  }// switch
  //
} // func

void keyPressedForstateMenu_jogar() {
  // any key is possible
  switch(key) {
  case '4':
    state = jogar_normal;
    break;
  case '5' :
    state = jogar_normal_audio;
    break;
  case 'x':
  case 'X':
    state = stateMenu;
    break;
  default:
    state = stateMenu_jogar;
    break;
  } // switch
  //
} // func
void keyPressedFordefinicoes_gerais() {
  // any key is possible
  switch(key) {
  default:
    state = stateMenu;
    break;
  } // switch
  //
} // func
void keyPressedForanalise_dados() {
  // any key is possible
  switch(key) {
  default:
    state = stateMenu;
    break;
  } // switch
  //
} // func

void keyPressedForjogar_normal() {
  // any key is possible
  switch(key) {
  default:
    state = jogar_normal;
    break;
  } // switch
  //
} // func
void keyPressedForjogar_normal_audio() {
  // any key is possible
  switch(key) {
  default:
    state = jogar_normal_audio;
    break;
  } // switch
  //
} // func

// ----------------------------------------------------------------
// functions to show the menu and functions that are called from the menu.
// They depend on the states and are called by draw().

void showMenu() {
  println ("jdsh");
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" Jogo da Memória ", 150, 100, 3);
  textSize(14);
  text("Press 1 para Jogar ", 100, 200);
  text("Press 2 para Definições Gerais ", 100, 220);
  text("Press 3 See Análise de Dados", 100, 240);
  //
  text("Press x para sair ", 100, 260);
  //
} // func

void handlestateMenu_jogar() {
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" Escolhe jogo ", 150, 100, 3);
  textSize(14);
  text("4 - Jogar jogo normal", 100, 200);
  text("5 - Jogar jogo audio", 100, 300);
  text("x - voltar ao menu", 100, 400);
  //
} // func
//

void handledefinicoes_gerais() {
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" Ver definições gerais ", 150, 100, 3);
  textSize(14);
  text("… some text ", 100, 200);
  //
} // func

void handleanalise_dados() {
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" Ver analise_dados ", 150, 100, 3);
  textSize(14);
  text("… some text ", 100, 200);
  //
} // func

void handlejogar_normal() {
  background(255, 204, 0);
  //fill(0);
  //textSize(32);
  //text(" colocar jogos normais ", 150, 100, 3);
  //textSize(14);
  //text("jogo ", 100, 200);
  //
} // func

void handlejogar_normal_audio() {
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" colocar jogo normais e audio ", 150, 100, 3);
  textSize(14);
  text(" jogo ", 100, 200);
  //
}

// ----------------------------------------------------------------
//

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 2, 2020, 1:16pm UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/5 "2020-04-02T13:16:41Z")

</div>

- [Forum.Processing.org/two/discussions/tagged/JPasswordField](http://Forum.Processing.org/two/discussions/tagged/JPasswordField)

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 2, 2020, 2:05pm UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/6 "2020-04-02T14:05:56Z")

</div>

Hello,

Please format your code as a courtesy to everyone:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

---

<div class="post-metadata">

**Author:** ![DaysLoop](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@DaysLoop](https://discourse.processing.org/u/DaysLoop)\
**Post date:** [April 2, 2020, 4:06pm UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/7 "2020-04-02T16:06:43Z")

</div>

Thanks Bro and I’m sorry. Now will go use this

---

<div class="post-metadata">

**Author:** ![DaysLoop](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@DaysLoop](https://discourse.processing.org/u/DaysLoop)\
**Post date:** [April 2, 2020, 4:07pm UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/8 "2020-04-02T16:07:29Z")

</div>

thank you very much.

---

<div class="post-metadata">

**Author:** ![DaysLoop](https://avatars.discourse-cdn.com/v4/letter/d/ce7236/32.png) [@DaysLoop](https://discourse.processing.org/u/DaysLoop)\
**Post date:** [April 3, 2020, 9:58am UTC](https://discourse.processing.org/t/renderer-problems-login-system-and-menu/19331/9 "2020-04-03T09:58:06Z")

</div>

Problem Resolved:

```auto
//Bibliotecas
import static javax.swing.JOptionPane.*;
import javax.swing.JPasswordField;

//Variaveis
boolean validar = false;

//Uma classe simples para usar uma String como uma pesquisa para um valor de String. As “chaves” da sequência estão associadas aos valores da sequência.
final StringDict accounts = 
  new StringDict(
  new String [] {
  "baptiste", "tanguy", "alexis"
  }, 
  new String [] {
    "bap", "guy", "ex"
  }
  );

final JPasswordField pwd = new JPasswordField();

{
  println(accounts);
}

//menu
// states
final int stateMenu = 0;
final int stateMenu_jogar = 1;
final int definicoes_gerais = 2;
final int analise_dados = 3;
final int jogar_normal = 4;
final int jogar_normal_audio = 5;
int state = stateMenu;
//
//

//------

void setup() {
  size(700, 800);
  smooth();

  textAlign(CENTER, CENTER);
  rectMode(CENTER);

  fill(255);
  strokeWeight(2);
  //login();
boolean validar = login();
while (!validar){
validar = login(); println(validar);}
}

//------

void draw() {
  background(255, 204, 0);

  menu();
 }

//-----Login

void login() {
  boolean isLogged = false;
  if (frameCount == 1) surface.setVisible(false);

  String user = askUser();

  if (user == null) 
    confirmQuit();
  else if (!"".equals(user))
    isLogged = askPass(user);
    return isLogged;
}

String askUser() { //tela pergunta utilizador
  String id = showInputDialog("Please enter user:"); //dialogo inicial

  if (id == null) //caso a resposta seja carregar na tecla cancelar
    showMessageDialog(null, "You’ve canceled login operation!", "Alert", ERROR_MESSAGE);

  else if ("".equals(id)) //caso a resposta seja sem colocar dados
    showMessageDialog(null, "Empty user input!", "Alert", ERROR_MESSAGE);

  else if (!accounts.hasKey(id = id.toLowerCase())) //caso a resposta seja a errada
    showMessageDialog(null, "UnKnown \"" + id + "\" user!" + (id = ""), "Alert", ERROR_MESSAGE);

  return id;
}

boolean askPass(String id) {

  boolean isLogged = false;
  pwd.setText("");

  int action = showConfirmDialog(null, pwd, "Now enter password:", OK_CANCEL_OPTION);

  if (action != OK_OPTION) {
    showMessageDialog(null, "Password input canceled!", "Alert", ERROR_MESSAGE);

    return false;
  }

  //String phrase = pwd.getText();
  String phrase = new String(pwd.getPassword());

  if ("".equals(phrase)) {
    showMessageDialog(null, "Empty password input!", "Alert", ERROR_MESSAGE);
  } else if (accounts.get(id).equals(phrase)) { //password correta
    showMessageDialog(null, "Welcome "
      + id
      +
      "!\nYou’re logged in!", 
      "Infor", 
      INFORMATION_MESSAGE);

    isLogged = true;

  } else {
    showMessageDialog(null, 
      "Password " + phrase + " mismatch!", "Alert!", ERROR_MESSAGE);
  }

  return isLogged;
}

void confirmQuit() {
  if (showConfirmDialog(null, 
    "Wanna quit then?", "Exit", OK_CANCEL_OPTION) == OK_OPTION)
    exit();
}

void menu() {
  // the main routine. It handels the states.
  // runs again and again
  switch (state) {
  case stateMenu:
    showMenu();
    break;
  case stateMenu_jogar:
    handlestateMenu_jogar();
    break;
  case definicoes_gerais:
    handledefinicoes_gerais();
    break;
  case analise_dados:
    handleanalise_dados();
    break;
  case jogar_normal:
    handlejogar_normal();
    break;
  case jogar_normal_audio:
    handlejogar_normal_audio();
    break;
  default:
    println ("Unknown state (in draw) "
      + state
      + "++++++++++++++++++++++");
    exit();
    break;
  } // switch
  //
}//

// ----------------------------------------------------------------
// keyboard functions

void keyPressed() {
  // keyboard. Also different depending on the state.
  switch (state) {
  case stateMenu:
    keyPressedForStateMenu();
    break;
  case stateMenu_jogar:
    keyPressedForstateMenu_jogar();
    break;
  case definicoes_gerais:
    keyPressedFordefinicoes_gerais();
    break;
  case analise_dados:
    keyPressedForanalise_dados();
    break;
  case jogar_normal:
    keyPressedForjogar_normal();
    break;
  case jogar_normal_audio:
    keyPressedForjogar_normal_audio();
    break;
  default:
    println ("Unknown state (in keypressed) "
      + state
      + " ++++++++++++++++++++++");
    exit();
    break;
  } // switch
  //
} // func

void keyPressedForStateMenu() {
  //
  switch(key) {
  case '1':
    state = stateMenu_jogar;
    break;
  case '2':
    state = definicoes_gerais;
    break;
  case '3':
    state = analise_dados;
    break;
  case '4':
    state = jogar_normal;
    break;
  case '5' :
    state = jogar_normal_audio;
    break;
  case 'x':
  case 'X':
    // quit
    exit();
    break;
  default:
    // do nothing
    break;
  }// switch
  //
} // func

void keyPressedForstateMenu_jogar() {
  // any key is possible
  switch(key) {
  case '4':
    state = jogar_normal;
    break;
  case '5' :
    state = jogar_normal_audio;
    break;
  case 'x':
  case 'X':
    state = stateMenu;
    break;
  default:
    state = stateMenu_jogar;
    break;
  } // switch
  //
} // func
void keyPressedFordefinicoes_gerais() {
  // any key is possible
  switch(key) {
  default:
    state = stateMenu;
    break;
  } // switch
  //
} // func
void keyPressedForanalise_dados() {
  // any key is possible
  switch(key) {
  default:
    state = stateMenu;
    break;
  } // switch
  //
} // func

void keyPressedForjogar_normal() {
  // any key is possible
  switch(key) {
  default:
    state = jogar_normal;
    break;
  } // switch
  //
} // func
void keyPressedForjogar_normal_audio() {
  // any key is possible
  switch(key) {
  default:
    state = jogar_normal_audio;
    break;
  } // switch
  //
} // func

// ----------------------------------------------------------------
// functions to show the menu and functions that are called from the menu.
// They depend on the states and are called by draw().

void showMenu() {
  println ("jdsh");
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" Jogo da Memória ", 150, 100, 3);
  textSize(14);
  text("Press 1 para Jogar ", 100, 200);
  text("Press 2 para Definições Gerais ", 100, 220);
  text("Press 3 See Análise de Dados", 100, 240);
  //
  text("Press x para sair ", 100, 260);
  //
} // func

void handlestateMenu_jogar() {
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" Escolhe jogo ", 150, 100, 3);
  textSize(14);
  text("4 - Jogar jogo normal", 100, 200);
  text("5 - Jogar jogo audio", 100, 300);
  text("x - voltar ao menu", 100, 400);
  //
} // func
//

void handledefinicoes_gerais() {
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" Ver definições gerais ", 150, 100, 3);
  textSize(14);
  text("… some text ", 100, 200);
  //
} // func

void handleanalise_dados() {
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" Ver analise_dados ", 150, 100, 3);
  textSize(14);
  text("… some text ", 100, 200);
  //
} // func

void handlejogar_normal() {
  background(255, 204, 0);
  //fill(0);
  //textSize(32);
  //text(" colocar jogos normais ", 150, 100, 3);
  //textSize(14);
  //text("jogo ", 100, 200);
  //
} // func

void handlejogar_normal_audio() {
  background(255, 204, 0);
  fill(0);
  textSize(32);
  text(" colocar jogo normais e audio ", 150, 100, 3);
  textSize(14);
  text(" jogo ", 100, 200);
  //
}

// ----------------------------------------------------------------
//

```

Thank for your help! 🙂
