Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to close this window?

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try using the "dispose()" method.
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot - that worked!
 
Rob Camick
Ranch Hand
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Don't you think you will have the same problem with the above statement?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have also faced this problem.
This post has helped me to solve it.
Thank You
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic