-
JOptionPane Basics
Cant seem to get Joption pane working. I have a feeling that its something really basic that I am doing.
Here is the function that I am having issues with:
Code:
private static void mainMenu() // Main menu function. This menu greets user
{
Scanner input = new Scanner(System.in); // Declare Scanner
int choice = 0;
// Start of do while loop for main menu
do{
choice = JOptionPane.showInputDialog(
"Please enter the menu number:"
,null
,"1. Add Prisoner"
,"2. Information on Prisoner"
,"3. Display Current Prisoners"
,"0. Exit");
if(choice==1)
{
newPrisoner(); // Function call
}
else if(choice==2)
{
prisonerReport(); // Function call
}
else if(choice==3)
{
currentPrisoners();// Function call
}
}while(choice!=0); // end of loop
}
This is what I have so far but I get an error with the JOptionPane.showInputDialog. I think its that I declared choice as a int and its meant to be a string. If that is the case how can I get it to work by getting the user to enter the menu number?
-
Change choice to a String sowInputDialog returns a String
declare and Object array for your choices to display and add it to your
option pane
Code:
Object[]choicesArr={"1. Add Prisoner"
,"2. Information on Prisoner"
,"3. Display Current Prisoners"
,"0. Exit"};
choice = JOptionPane.showInputDialog(
null,choicesArr);
Then you need to parse choice to an int
Code:
int ch=Integer.parseInt(choice);