Ich habe ein Programm in Java erstellt, das versucht, ein Popup-Menü zu erstellen, das Ihnen Auswahlmöglichkeiten bietet.Wie bringt man einen Code zurück zum Hauptmenü?
Ich habe die Auswahl und wie alles funktioniert, aber ich kann nicht scheinen, es so zu bekommen, wenn Sie Ihren Benutzernamen und Ihr Passwort erstellen, bringt Sie zurück zum Hauptmenü.
Alles für das?
import javax.swing.*;
public class MyOwn {
/**
* @author Noah
*/
public static void main(String[] args) {
Object[] options = {
"Create Login",
"Login",
"Quit"
};
int menuOption = JOptionPane.showOptionDialog(null, "Please choose the " + "program you would like to run:", "Program Menu", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[2]);
boolean exit = false;
while (!exit) {
switch (menuOption) {
case 0:
String userName = JOptionPane.showInputDialog(null, "Create a username:", "johndoe");
String password = JOptionPane.showInputDialog(null, "Create a password:", "johndoe123");
exit = true;
break;
case 1:
String userNameEntry = JOptionPane.showInputDialog(null, "Enter your username:");
String passwordEntry = JOptionPane.showInputDialog(null, "Enter your password:");
if (userName.equals(userNameEntry) && password.equals(passwordEntry)) {
Object[] optionsTwo = {
"Season Quiz",
"Profile Analysis",
"Piggy Bank"
};
int menuOptionTwo = JOptionPane.showOptionDialog(null, "Please choose the " + "program you would like to run:", "Program Menu", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, optionsTwo, optionsTwo[2]);
switch (menuOptionTwo) {
case 0:
System.out.println("Season Quiz");
break;
case 1:
System.out.println("Profile Analysis");
break;
case 2:
System.out.println("Piggy Banks");
break;
}
}
break;
case 2:
System.exit(0);
default:
break;
}
}
}
}
Irgendwelche Vorschläge bitte?