Why doesn’t this Swing-based program terminate when its window is closed?
import javax.swing.JFrame;
import javax.swing.JOptionPane;
final class App extends JFrame {
private App() {
super("App");
setDefaultCloseOperation(EXIT_ON_CLOSE);
JOptionPane.showMessageDialog(this, "App works");
pack();
}
public static void main(final String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new App().setVisible(true);
}
});
}
}
It doesn’t terminate on anyone’s system, first of all.
The reason is because you are calling a JFrame to be set visible with zero contents. It’s most likely hiding very very small in the upper left hand corner of your screen. If you close that frame your program will terminate. The message dialog has nothing to do with the JFrame.