I have a project that I'm working on a project that requires 2 JFrames in a single program. The problem is that when I close one the other will also close so I made a test class to see what the issue was and I still couldn't figure it out so here is the test case that I have:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class frameTest {
public static void main(String[] args) {
JFrame f1 = new JFrame();
JButton open = new JButton("open");
open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JFrame f2 = new JFrame();
f2.setVisible(true);
f2.setDefaultCloseOperation(f2.EXIT_ON_CLOSE);
f2.setSize(200, 200);
}
});
f1.setDefaultCloseOperation(f1.EXIT_ON_CLOSE);
f1.setVisible(true);
f1.setSize(500, 500);
f1.add(open);
}
}
When I click the open button the popup (f2) will appear but when I close it the other window will also close, why does this happen?