• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program doesn't close though WindowClosing Event called  RSS feed

 
Ryan Daguman
Ranch Hand
Posts: 33
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I have a program here that doesn't, I hope I use the right term, release resources because after clicking the close button, the DOS prompts becomes unresponsive. So I have to close the DOS prompt, then reopen it, then type in the path again for the Java folders. Can you check where did I go wrong with my code? Is my placement of the WindowListener and WindowAdapter incorrect? Please refer to my code below:



Please help me because I have other programs where the placement of the WindowListener and WindowAdapter are as exactly like this (within the class constructor block) where they close correctly and some that behave like this, that renders the DOS prompt unresponsive. Your inputs will be greatly appreciated. Thank you!
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Release the resources" is an OK way to put it, although "exit the application" would probably be clearer. It doesn't look like you ever call addWindowListener(), so it's not surprising that the System.exit(0) there never gets called. In any case, that's a very badly outdated way of handling the close operation. Get rid of the WindowAdapter, and instead call this in your Proj6exe1 constructor:

Then, get rid of all those System.exits in the the button's action handler, and put in:

I think that should work! I'll move this thread over to our GUI forum to let the real experts weigh in on it.
 
Ryan Daguman
Ranch Hand
Posts: 33
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Mr. Greg Charles. Yes it did work. I appreciate your inputs. The use AddWindowListener() makes it evident that I'm using an old Java book. It's actually published in 2001, therefore, it's Java 2 SDK and JRE 1.2 during that time. I think I'll buy a new Java book that focuses on, at least, Java 5 or 6 but 7 would be preferable.
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
2001? So that explains all the other old-fashioned features of your code. Yes, the book should be discarded immediately.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote: . . . Yes, the book should be discarded immediately.
Put in a museum instead, surely?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!