Results 1 to 3 of 3
  1. #1
    kris5228 is offline Member
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

    Question JFrame making it do an action on exit

    Hello,

    I want to make my program do something else than

    Java Code:
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    How do i call a class from another java file when pressing the X?

    I've already made a file that looks like this:

    Java Code:
    public class Exit
    {
        private static Main mainfile = new Main();
    
        public void onexit()
        {
            if (mainfile.fn.equals("unnamed"))
            {
                Object[] options = { "SAVE", "NO", "CANCEL"};
    
                JOptionPane.showOptionDialog(null, "Do you want to save " + mainfile.fn + "?", "Warning",
                                            JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
            }
            else
            {
                mainfile.frame.dispose();
            }
        }
    }
    All i need is to make the Exit Button execute that.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

  3. #3
    kris5228 is offline Member
    Join Date
    Nov 2011
    Posts
    17
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 06-30-2011, 10:49 AM
  2. How do I stop the program but not exit the JFrame?
    By rajkobie in forum New To Java
    Replies: 1
    Last Post: 04-23-2011, 04:53 PM
  3. Replies: 4
    Last Post: 07-29-2010, 03:53 PM
  4. Could not find main class: Jframe. Program will exit.
    By egbert95 in forum Advanced Java
    Replies: 8
    Last Post: 07-29-2010, 03:53 PM
  5. Making a JApplet into a JFrame into a .jar
    By aqualicy in forum Java Applets
    Replies: 2
    Last Post: 05-14-2010, 05:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •