main - why doesn't it exit after a JFrame is created?

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. ???

When you make the JFrame visible, the AWT Event Dispatch Thread starts waiting for events. Since that Thread is still running, the program is still running.

The fact that the default Thread for the program is over is irrellevant so long as at least one Thread is running.

[quote="fletchergames,post:2,topic:29525"] Thread is running. [/quote]

thanks fletchergames!