Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I instantiate a new object of an already designed jdialog with command buttons "yes" and "no", I implemented the new object on the windowClosing event of a JFrame form but I dont know how to carry out an operation such as closing the form if the button "yes" is been clicked or the not doing any thing if button "no" is been clicked.
Can you put me through please?

[HB Edit: removed bold and large font]
Posted
Updated 28-Jul-13 16:41pm
v2

Java
if(yes){
   frameObj.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}else{
   frameObj.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}
 
Share this answer
 
Comments
Showlar 12-Mar-13 23:59pm    
if(yes){
frameObj.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}else{
frameObj.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
}

"yes" oin that quote is what? Is it a boolean or variable name. Please help me.
Where will I put this code ? Is it in the jframe form class or the jdialog class. The name of these two buttons are cmdYes and cmdNo respectively.
Many thanks.
Shubhashish_Mandal 13-Mar-13 2:52am    
here "yes" represent that you want to close. The value of yes coming from your dialog.
Read before doing anything. Here is the link for this purpose.

http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
I make the two buttons public and then I make a Boolean to change anytime the button is clicked. Meanwhile the Boolean is false inside the constructor. Therefore I can check the value of the Boolean variable before taking actions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900