Results 1 to 5 of 5

Thread: When a JFrame Is Closed Exit From an Application

  1. #1
    Join Date
    Nov 2009
    Posts
    877

    When a JFrame Is Closed Exit From an Application

    Hello, I am working on the project in java and while making use of it, I want to do something from which when I will Close the frame it will simply exit from the application which I am working. So, if you are having any solution to achieve it, then please help me to get the solution. I am not able to get the solution for it.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: When a JFrame Is Closed Exit From an Application

    Hello, you need to use the following properties for getting the solution in this problem:

    • DISPOSE_ON_CLOSE
    • DO_NOTHING_ON_CLOSE
    • EXIT_ON_CLOSE
    • HIDE_ON_CLOSE

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: When a JFrame Is Closed Exit From an Application

    Hey, I think if you simply make use of the code below then you will able to get the solution for your problem:
    Code:
    JFrame frame= new JFrame();
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter()
    {
    public void windowClosing(WindowEvent we)
    {
    exitProcedure();
    }
    });

  4. #4
    Join Date
    Apr 2008
    Posts
    1,948

    Re: When a JFrame Is Closed Exit From an Application

    Hello, I have the small code below which will help you to achieve the thing which you want:
    Code:
    import javax.swing.JFrame;
    
    public class Main
    {
      public static void main(String[] argv) throws Exception
     {
        JFrame fr = new JFrame();
        int checker = fr.getDefaultCloseOperation();
        fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      }
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,012

    Re: When a JFrame Is Closed Exit From an Application

    First thing you will need to do is to get the close operaton by default. For that use the code below:
    Code:
    JFrame frm = new JFrame();
    Now you need to use the code line below:
    Code:
    int op = frm.getDefaultCloseOperation();
    After this you just need to use the EXIT_ON_CLOSE property for exiting the window.
    Code:
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Similar Threads

  1. in Toshiba thrive, how to completely exit application?
    By Turquose in forum Portable Devices
    Replies: 5
    Last Post: 28-11-2011, 11:06 PM
  2. How to exit an application in windows phone 7?
    By Garonman in forum Portable Devices
    Replies: 5
    Last Post: 27-10-2010, 12:22 AM
  3. Exit a Silverlight Application
    By KornFlexia in forum Portable Devices
    Replies: 4
    Last Post: 26-10-2010, 07:43 PM
  4. Raise without a handler, Application will exit.
    By Bower in forum Windows Software
    Replies: 5
    Last Post: 15-07-2010, 01:47 PM
  5. Fatal Application Exit Notification Won't Go Away
    By gabrielconroy in forum Operating Systems
    Replies: 3
    Last Post: 19-05-2009, 08:05 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,038,809.57595 seconds with 17 queries