Yours is a common Swing newbie error, and while yes, you could set the JFrame default close operation to DO_NOTHING_ON_CLOSE
, you're then still stuck with a bad program design.
Instead, you should almost never display two JFrames at once as a JFrame is meant to display a main application window, and most applications, including and especially professional applications don't have multiple application windows. Instead, make the "mother" window a JFrame, and the child or dependent Window a JDialog, and your problem is solved in that when the child window closes, the application must remain open. The JDialog has the additional advantage of allowing it to be either modal or non-modal as the need dictates.
Other decent solutions including avoiding multiple windows altogether including use of JTabbedPane or the CardLayout to swap views.
Please read: The use of multiple JFrames, good bad practice
Edit
For example
import java.awt.Dialog.ModalityType;
import java.awt.Dimension;
import javax.swing.*;
public class DialogEx {
private static void createAndShowGui() {
JFrame frame1 = new JFrame("DialogEx");
frame1.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame1.setUndecorated(true);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setVisible(true);
JDialog nonModalDialog = new JDialog(frame1, "Non-Modal Dialog", ModalityType.MODELESS);
nonModalDialog.add(Box.createRigidArea(new Dimension(200, 200)));
nonModalDialog.pack();
nonModalDialog.setLocationByPlatform(true);
nonModalDialog.setVisible(true);
JDialog modalDialog = new JDialog(frame1, "Modal Dialog", ModalityType.APPLICATION_MODAL);
modalDialog.add(Box.createRigidArea(new Dimension(200, 200)));
modalDialog.pack();
modalDialog.setLocationByPlatform(true);
modalDialog.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGui();
}
});
}
}