Reputation: 53
I am making a small Java project in which there are 3 frames connected together, say f1
, f2
, f3
& f4
. f1
is having a button and after clicking it it calls f2
and f2
also has button which calls f3
. The problem is if I opened all the form one by one then when I close form f2
or f3
then the main form(f1
) gets closed.
I want that even I close form f2
and f3
my main form should not be close until I close it personally.
package mnm;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
NewJFrame1 nb=new NewJFrame1();
nb.setVisible(true);
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
NewJFrame gn=new NewJFrame();
gn.setDefaultCloseOperation(NewJFrame.DISPOSE_ON_CLOSE);
}
});
}
private javax.swing.JButton jButton1;
}
Upvotes: 0
Views: 1091
Reputation: 168825
..3 frames connected together
Don't do it! See The Use of Multiple JFrames, Good/Bad Practice? for details. Two of those frames should be either modal dialogs or a JOptionPane
.
I want that even I close form
f2
andf3
my main form should not be close until I close it personally.
Now that I've warned you against it, I'll add..
The behavior requested can be achieved by setting a default close operation of DISPOSE_ON_CLOSE
as seen in this answer. Any of those frames can be closed without affecting the others.
Upvotes: 5