You are being forwarded to the lastest updates ot his page!
Or you can Click Here if it doesn't work or you don't wish to wait.

JOptionPane question

Katie McCann
I'm writing a Java application with a JOptionPane that prompts the user whether or not they want to save their changes. Here' the relevant lines of code:

1. JOptionPane dialog= new JOptionPane();

2. dialog.showConfirmDialog(this,"Do you want to save your changes?", "Save Changes?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null);

3. Object selectedValue= dialog.getValue();

4. System.out.print(selectedValue);

Why is line 4 always printing out "uninitializedValue" after I select an option from the JOptionPane. (I only added in line 4 for debugging purposes, but it shows what the problem is).

Thanks in advance!


deekasha gunwant
hi kaity,
the value selected by the user is returned by the function showConfirmDialog itself.(i've used it successfully)
so u try using
int selectedValue = dialog.showConfirmDialog(this,.....);
System.out.print(selectedValue);

hope this is of some help
deekasha


maheswari
Actually, I have used this JOptionPane.showConfirm(...)
return out in switch case. i.e the showConfirm() method
itself return integer value. so store this return value into
integer type. and do it in following way
val=JOptionPane.showConfirm(...)
switch(val)
{
case JOptionPane.YES_OPTION:
do something.
case JOptionPane.NO_OPTION:
do something....
}