File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 20275

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: 2451
Read the JFrame API to see what the default value is for that method. Once you know the default you should understand the behaviour.
I agree. Here's the link:
subject: swing ques- JFrame
jQuery in Action, 3rd edition