• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Not able to resume command promt after using swings

 
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....
 
Marshal
Posts: 65114
247
  • 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 !

 
Sheriff
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Marshal
Posts: 65114
247
  • 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
Posts: 21775
103
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or a shutdown hook.
 
Campbell Ritchie
Marshal
Posts: 65114
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I forgot about shutdown hooks. They're nice things to use
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • 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
Boost this thread!