Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Not able to resume command promt after using swings

 
aarav cheruk
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


The above programs works fine..iam getting a window when i close the window thro 'x' button on top right...

my command promt doesnt close, it shows the same thing, java help

how do i resume back my command prompt like any other java program.

Any help is of great use...Thanks in advance....
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Please use the code button; since you are new I have edited your post and you can see how it improves the look of your code and makes the indentation errors easier to find

You need to go through the JFrame documentation and look what happens when you close a frame. Also find out about threads in Swing; the "main" thread is still running at this point. That is probably your problem.

I shall move this discussion to the Swing (not "swings") forum.
 
aarav cheruk
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hey sheriff,

Thanks for your post...as well as editing my post using code.

yup am new both to java and this forum.

I got the solution...its simple....

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

which I dint know earlier about !

 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That works fine if your application only has one JFrame. If it can have multiple then JFrame.DISPOSE_ON_CLOSE is a better option. Once the last JFrame has been disposed the Event Dispatcher Thread will end and so will your program (provided there are no other non-daemon threads running).
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:That works fine if your application only has one JFrame. . . .
. . . and you have no other actions you wish to perform while the frame closes, eg saving something to a file. When the JVM exits, the file might only be partially written, and may be corrupted. In that case a WindowListener can be used to do the file writing on closing.
 
Rob Spoor
Sheriff
Pie
Posts: 20532
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or a shutdown hook.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I forgot about shutdown hooks. They're nice things to use
 
Darryl Burke
Bartender
Posts: 5126
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:TOnce the last JFrame has been disposed the Event Dispatcher Thread will end and so will your program (provided there are no other non-daemon threads running).

One situation I'm aware of that causes the EDT to not terminate is when a Swing Timer is still running. And one way to guard against that in a situation that makes it difficult to code for stopping the Timer is to include a check in its actionPerformed:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic