This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program wont terminate

 
Jonathan Steel
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic