| Author |
How yo use JOptionPane.showInputDialog()
|
Varuna Seneviratna
Ranch Hand
Joined: Jan 15, 2007
Posts: 164
|
|
Since numbers[] is an integer array, what is the way to convert the String type to integer type when entered into the showInputDialog box. Varuna
|
Varuna Seneviratna
|
 |
Zaynab Ejaz
Greenhorn
Joined: Nov 14, 2008
Posts: 6
|
|
String input = JOptionPane.showInputDialog("Input Number"); numbers[i] = Integer.parseInt(input); input is a String variable holding the value entered in the JOptionPane then that variable is converted using Integer.parseInt() method and saved in the integer array (numbers[i]).
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Slight alteration required. If you look up the JOptionPane.html#showInputDialog() method, it takes at least two arguments. If you are using a non-GUI application it is probably easiest to pass null for the first argument. Then the dialogue appears in the centre of the screen. Beware: it seems to have a habit of hiding behind other windows, so you may have to search the screen to find it. Beware: It is a "modal" dialogue. Until you have dismissed the dialogue, you may not get the remainder of your application to do anything.
|
 |
Varuna Seneviratna
Ranch Hand
Joined: Jan 15, 2007
Posts: 164
|
|
Originally posted by Campbell Ritchie: Slight alteration required. If you look up the JOptionPane.html#showInputDialog() method, it takes at least two arguments. If you are using a non-GUI application it is probably easiest to pass null for the first argument. Then the dialogue appears in the centre of the screen.
According to the API description it does not say where the dialouge will appear, How do you say that if null is passed as the first argument value the dialouge will appear at the centre of the screen.I am asking this is because I want to learn how to understand the API. Regards Varuna
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
That's what always seems to happen when I try it. I went through the code to see if I could find anything helpful there . . . and got lost
|
 |
Zaynab Ejaz
Greenhorn
Joined: Nov 14, 2008
Posts: 6
|
|
If you look up the JOptionPane.html#showInputDialog() method, it takes at least two arguments.
as I see It the JOptionPane.showInputDialog() methods takes only one argument, am I missing something??
|
 |
Brian Lang
Ranch Hand
Joined: Oct 21, 2008
Posts: 43
|
|
Originally posted by Varuna Seneviratna: According to the API description it does not say where the dialouge will appear, How do you say that if null is passed as the first argument value the dialouge will appear at the centre of the screen.I am asking this is because I want to learn how to understand the API.
You didn't bother to read the entire page. Take a look at the section labeled 'parentComponent' (the first argument). JOptionPane Whoops, link didn't work. [ November 16, 2008: Message edited by: Brian Lang ]
|
 |
Brian Lang
Ranch Hand
Joined: Oct 21, 2008
Posts: 43
|
|
Originally posted by Zaynab Ejaz: as I see It the JOptionPane.showInputDialog() methods takes only one argument, am I missing something??
Yes. It's overloaded into several different methods with different signatures. Take a look at the API page again, noting the different versions of showInputDialog. Wow, I don't know what's up with the URLs today. [ November 16, 2008: Message edited by: Brian Lang ]
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
Brian Lang is right; it is overloaded. I may have missed the one-arg version, where the parent defaults to null. If so, sorry for misinforming you.
|
 |
Varuna Seneviratna
Ranch Hand
Joined: Jan 15, 2007
Posts: 164
|
|
Originally posted by Campbell Ritchie: That's what always seems to happen when I try it. I went through the code to see if I could find anything helpful there . . . and got lost
What do you mean by the above?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
I read the original code to see whether it would give some idea about the location of the dialogue when parent was null . . . And I couldn't follow it back in the JDialog class.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
Whenever I use JOptionPane without a GUI, the dialogue appears in the middle of the screen. If there are other windows there, the dialogue may disappear behind the other windows, and I have to minimise things to find the dialogue.
|
 |
 |
|
|
subject: How yo use JOptionPane.showInputDialog()
|
|
|