• Post Reply Bookmark Topic Watch Topic
  • New Topic

JOptionPane.showConfirmDialog choice problem

 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to check where the user made yes or no
please help me


if (new File(saveFileChooser.getSelectedFile().getAbsolutePath()).exists()){
JOptionPane.showConfirmDialog(saveFileChooser, "File already exists \n overwrite it ?","Error",0, 3);
//i want to add her code to check if user pressed yes or no
//but i dont know how to do it

}
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are almost there. The showConfirmDialog method returns one of the constants YES_OPTION or NO_OPTION (also CANCEL_OPTION etc if you pass in different parameters).

Just check for the return value of the method like this:

Note also how I have used the constant names instead of the numbers in the method call. It is much easier to understand the code this way
[ August 16, 2005: Message edited by: Stuart Gray ]
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Stuart Gray
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!