Results 1 to 2 of 2
  1. #1
    eolas is offline Member
    Join Date
    Feb 2011
    Rep Power

    Default 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:

    Java Code:
    private static void mainMenu()  // Main menu function. This menu greets user
            Scanner input = new Scanner(; // Declare Scanner
            int choice = 0; 
            // Start of do while loop for main menu
                choice = JOptionPane.showInputDialog(
                        "Please enter the menu number:"
                        ,"1. Add Prisoner"
                        ,"2. Information on Prisoner"
                        ,"3. Display Current Prisoners"
                        ,"0. Exit");
                    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?

  2. #2
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Waterford, Ireland
    Rep Power


    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

    Java Code:
     Object[]choicesArr={"1. Add Prisoner"
                    ,"2. Information on Prisoner"
                    ,"3. Display Current Prisoners"
                    ,"0. Exit"};
     choice = JOptionPane.showInputDialog(
    Then you need to parse choice to an int

    Java Code:
    int ch=Integer.parseInt(choice);
    Last edited by al_Marshy_1981; 02-28-2011 at 09:46 PM.

Similar Threads

  1. the very very very basics of java2d
    By senca in forum New To Java
    Replies: 1
    Last Post: 11-24-2010, 04:30 PM
  2. Basics
    By avish12 in forum SWT / JFace
    Replies: 2
    Last Post: 06-09-2010, 03:04 PM
  3. Really Basics
    By Taluntain in forum New To Java
    Replies: 16
    Last Post: 10-08-2009, 09:43 AM
  4. About swing basics
    By harithaspa in forum AWT / Swing
    Replies: 2
    Last Post: 12-13-2008, 01:07 PM
  5. Basics
    By AKP in forum New To Java
    Replies: 7
    Last Post: 05-23-2008, 12:06 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts