my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes Program wont terminate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Program wont terminate" Watch "Program wont terminate" New topic
Author

Program wont terminate

Jonathan Steel
Greenhorn

Joined: Jan 26, 2005
Posts: 13
When I run the code below everything works as it should when a parameter is passed. But if no parameter is passed then the message box is displayed, I press ok, and then nothing happens. The program continues to run.

public static void main(String[] args) {
if (args.length == 1) {
CImageViewerDispatch ivd = new CImageViewerDispatch(args[0]);
}
else {
JOptionPane.showMessageDialog(null, "Wrong number of arguments in program parameter list");
}

return;
}

Do i need to release the message box from memory or something?
Tad Dicks
Ranch Hand

Joined: Nov 16, 2004
Posts: 264
you need a system exit call.

System.exit(0)

call this on close of the window. Or on return from the Dialog message.


-Tad
xxx yyyy
Greenhorn

Joined: Feb 20, 2005
Posts: 2
When you call JOptionPane.showMessageDialog(...) a Message Dialog (a Swing Component) is "realized". After this swing starts its event-dispatching thread.

Now you close the message dialog and the main-thread terminates, but
the swing event-dispatching thread is still running (the event-dispatching thread is not a "demeon" thread).
This is the reaseon why the VM does not exit.

Cheers,
Joern Kottmann
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program wont terminate