• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Code for JOptionPane buttons

 
Sandeep Swaminathan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How should one write code for the the YES, NO and CANCEL buttons of showConfirmDialog() of JOptionPane. Like if its YES then one must delete all the info from the database, NO then don't delete and CANCEL to go back!!
 
Maneesh Godbole
Saloon Keeper
Posts: 11064
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The showConfirmDialog returns an int which represents the user's choice. You typically trap the return value and process accordingly.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you check the return values, check them against JOptionPane.YES_OPTION (instead of == 0)
you also have to check for the user clicking 'X' or 'esc'

do you really need both "NO then don't delete and CANCEL to go back!!"
why not just YES_NO or OK_CANCEL
 
Sandeep Swaminathan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Michael n Maneesh,

Thanks a lot! That really helped me! And ya I don't need them both! Yes or No is more than enough :p
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic