Renderer Problems - Login System and Menu

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);
//
}

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

translate is only possible in P3D

So change size() in setup ()

1 Like

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.

interesting

The window dissapears.

Otherwise it works, aqui and jdsh both show up.

I think


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

is not compatible with processing.

We have to ask the gurus!

@GoToLoop

Chrisir



//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);
  //
}

// ----------------------------------------------------------------
//
1 Like
1 Like

Hello,

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

1 Like

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

thank you very much.

Problem Resolved:

//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! :slight_smile:

1 Like