20 easy points, Re: closing Frames

I have had the most trouble closing my Frames. I know the Frame ignores the Event.WINDOW_DESTROY. So without using System.exit(0), how can I get my Frames to close?
GilaMonsterAsked:
Who is Participating?
 
jpk041897Connect With a Mentor Commented:
Call the frames dispose() method.

dispose() destroys the frame. If thats not what you want, then you can call its diasable(true)  and setVisible(false) methods.
0
 
GilaMonsterAuthor Commented:
Thanks for the quick reply.

Your I have tried your suggestions. Here is the code that I thought would do the job; however, when I hit the 'X' in Win 95 to close the frame nothing happens.

Thanks

 public boolean handleEvent(Event event)
  {  
      if (event.id == Event.WINDOW_DESTROY)
      {
            hide();         // hide the Frame
            dispose();      // free the system resources
            System.exit(0); // close the application
            return true;
      }
      return super.handleEvent(event);
   }
0
 
jpk041897Commented:
What platform and JDK version are you running under?
0
 
jpk041897Commented:
Since a Frame is derived from Window, which is derived from container which is derived from component, you might want to try:

YourFrame.getParrent().remove(YourFrame);

and see if that works.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.