We help IT Professionals succeed at work.

20 easy points, Re: closing Frames

GilaMonster asked
Medium Priority
Last Modified: 2010-04-16
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?
Watch Question

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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


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.


 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);
What platform and JDK version are you running under?
Since a Frame is derived from Window, which is derived from container which is derived from component, you might want to try:


and see if that works.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.