| Author |
How to close this window?
|
miguel lisboa
Ranch Hand
Joined: Feb 08, 2004
Posts: 1281
|
|
i just dont know how to code this very simple situation: i have this first window that has a button which when clicked opens a second window;
this second window has a button that when clicked should close just this window, not the app
can anyone please help me?
thanks in advance
the working code follows
|
java amateur
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
|
You can try using the "dispose()" method.
|
Mohamed Sanaulla | My Blog
|
 |
miguel lisboa
Ranch Hand
Joined: Feb 08, 2004
Posts: 1281
|
|
mohamed sanaullah wrote:You can try using the "dispose()" method.
then i get this error message:
C:\...\CloseWindow.java:17: cannot find symbol
symbol: method dispose()
dispose(); }
^
1 error
Tool completed with exit code 1
when using it this way:
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
You should be using JFrame instance to call it. Its part of Window (I think?) class which gets inherited by JFrame. Also you would have to declare your JFrame reference as final in the CloseWindow class. (final- because the variables being used in the Anonymous Inner class (your ActionListener) must be declared as final)
Sorry for not being clear the first time.
|
 |
miguel lisboa
Ranch Hand
Joined: Feb 08, 2004
Posts: 1281
|
|
thanks a lot - that worked!
|
 |
Rob Camick
Ranch Hand
Joined: Jun 13, 2009
Posts: 1808
|
|
Don't you think you will have the same problem with the above statement?
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2946
|
|
Rob Camick wrote:
Don't you think you will have the same problem with the above statement?
The setDefaultCloseOperation would decide what to do with the JFrame when the user clicks on the Close button on the JFrame. I think by default it hides the Frame, but we would usually want to exit the Frame when we click on the Close button.
|
 |
Suganya Sampath
Greenhorn
Joined: Feb 15, 2012
Posts: 1
|
|
I have also faced this problem.
This post has helped me to solve it.
Thank You
|
 |
 |
|
|
subject: How to close this window?
|
|
|