Jump to content

Dialog Box trouble

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
wildbill

wildbill

    Newbie

  • Members
  • PipPip
  • 11 posts
I have been trying to get a dialog box with a combo box to come up when a button is pressed but I cannot figure out how to do it without creating my own form of a dialog box this is what I have so far

int row = 0;
        int column = 0;
        int[] rowOptions = {1,2,3,4,5,6,7,8,9,10};
        
        JFrame frame = new JFrame("Row Choice");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        

        
        row = JOptionPane.showInputDialog
        (frame,"Please enter the row of the seat you wish to view:\n",
         "Row Choice",
         JOptionPane.QUESTION_MESSAGE,null,
         rowOptions, "1")
the error I get is cannot find symbol - method showInputDialog(javax.swing.JFrame,java.lang.String,
java.lang.String,int,<nulltype>,int[].java.lang.String)

I would really appreciate any points in the right direction we are just learning about GUIs in class and I am going a little ahead of the pack in trying to use a dialog box to keep my main frame from being so cluttered.

#2
Guest_R3.RyozKidz_*

Guest_R3.RyozKidz_*
  • Guests
Are you trying to use javax.swing.JOptionPane ?
Actually you do not need to create any JFrame or anythings else when you are about using JOptionPane.

JOptionPane.showInputDialog actually will return a string .
You can do something like this . String input = JOptionPane.showInputDialog("Please enter your choice");

Or here is the link to Java API
JOptionPane (Java 2 Platform SE v1.4.2)

#3
wildbill

wildbill

    Newbie

  • Members
  • PipPip
  • 11 posts
I was using this web page as a reference How to Make Dialogs (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Swing Components)
I wanted to make mine like the one that has the combo box in it because I only want the user to be able to choose a number between 1 and 10 or i will get an out of bounds exception
and this seemed like the easiest way of error prevention the only problem is I don't know what to put for the frame and icon parameters.

#4
Guest_R3.RyozKidz_*

Guest_R3.RyozKidz_*
  • Guests
Hopefully this will help ..~
int user_input = 0;

do
{
    boolean cont = true;
    do
    {
        try
        {
            String x = JOptionPane.showInputDialog("Please enter your option");
            user_input = Integer.parseInt(x);
            cont = false;
        }
        catch(InputMismatchException inputMismatchException)
        {
            System.err.println(inputMismatchException);
            System.out.println("Please reenter it again");
        }
    } while (cont);

    if( user_input < 1 || user_input > 10);
    {
        System.out.println("Please reenter a valid option");
    }
} while( user_input < 1 || user_input > 10);

Or your try this code ?
Jframe frame = new JFrame();
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Object[] options = {"1", "2", "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10"};
String s = (String)JOptionPane.showInputDialog(
                    frame,
                    "Please choose your seat",
                    "Cinema Seats",
                    JOptionPane.PLAIN_MESSAGE,
                    null,
                    options,
                    "1");
And there is also a JRadioButton ..~

#5
wildbill

wildbill

    Newbie

  • Members
  • PipPip
  • 11 posts
Thank you very much this was super helpful.