How to get parent / ancestor frame control ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to get parent / ancestor frame control ?

Consider Situation 1 - i created a 4 different Java JFrames which has exit button, on click of exit button control goes to another frame which says Do you really want to close? and then on click of yes both frames should get closed

17th Oct 2017, 2:16 PM
Suyog Naikwade
Suyog Naikwade - avatar
1 Answer
+ 4
jframe.addEventListener(new java.awt.event.WindowAdapter(){//Adapter is like father of event,ha? @Override public int windowClosing(java.awt.event.WindowEvent evt){ if (javax.swing.JOptionPane.showConfirmDialog(frame, "Are you sure to close this window?", "Really Closing?", javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE) == javax.swing.JOptionPane.YES_OPTION){ frame.dispose(); //Every frame that want to close code } } }); //I still can't imagine situation though 😑
17th Oct 2017, 4:48 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar