I am wondering why a program like the below does not destroy the JFrame right after it’s creation, actually when main is left:
import java.awt.;
import javax.swing.;
import java.awt.event.*;
public class HelloWorld {
public static void main(String[] args) {
JFrame f = new JFrame(“This is a test”);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent event) {
System.exit(0);
}
});
f.setVisible(true);
}
}
After the setVisible there is no wait loop (do (while !bExit) {sleep(1);}…) or a message dispatcher (the latter being covered by swing I guess). The JFrame has only one reference, which is local to main. It should be destroyed when the end of main is reached, which happens almost immediately.
Especially strange is, the above program terminates when I leave out the setVisible. ???