Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane question  RSS feed

 
Katie McCann
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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....
}

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!