wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Not able to resume command promt after using swings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Not able to resume command promt after using swings" Watch "Not able to resume command promt after using swings" New topic
Author

Not able to resume command promt after using swings

aarav cheruk
Greenhorn

Joined: Oct 24, 2010
Posts: 2


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

Joined: Oct 13, 2005
Posts: 36453
    
  15
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

Joined: Oct 24, 2010
Posts: 2

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

Joined: Oct 27, 2005
Posts: 19538
    
  16

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


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
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

Joined: Oct 27, 2005
Posts: 19538
    
  16

Or a shutdown hook.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Yes, I forgot about shutdown hooks. They're nice things to use
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4522
    
    5

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:


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to resume command promt after using swings
 
Similar Threads
use JPanel more that two
Query on ProgressBar(Help plz)
Tally will not add up
Help designing a GUI
What is the best way to create GUI components- in-line, methods, inner classes or separate classes