This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes swing ques- JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "swing ques- JFrame" Watch "swing ques- JFrame" New topic

swing ques- JFrame

RajivAwadhesh kumar

Joined: May 20, 2011
Posts: 24
I tried a swing program from HeadFirst Java which is as following..

Its written in the book that if we use frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
the program will quit as soon as we close the window(if we leave this out
it will just sit there on the screen forever).

But when i dont use the above line the program closes as well , when i click the close button.
So whats the use of the above code line?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Did you recompile? Because what the book says is correct.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19908

The frame closes, but the JVM will continue to run. Just try it from the command line.

How To Ask Questions How To Answer Questions
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2261
Read the JFrame API to see what the default value is for that method. Once you know the default you should understand the behaviour.
subject: swing ques- JFrame