Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: What is the "JFrame.EXIT_ON_CLOSE" called?

  1. #1
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Smile What is the "JFrame.EXIT_ON_CLOSE" called?

    Hi,

    what is the "JFrame.EXIT_ON_CLOSE" called? It's not a method, I believe, it looks like something else. I would like to apply this to a framework called "SGUI" for my software. It doesn't contain any arguments, it's just a command for the JFrame. How could I make something like this?

    I ended up with making a method called setDialogType(SOptionPane.YES_NO_CANCEL()), but it's not the same thing. Does it have something to do with interface? Don't know what that is either, gonna do my homework now...

    Thanks fellows.


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,630
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: What is the "JFrame.EXIT_ON_CLOSE" called?

    It's just a static final int field; a constant. It has an integer value. Check out the API: JFrame (Java Platform SE 7 )
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Cronus (July 15th, 2013)

  4. #3
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Re: What is the "JFrame.EXIT_ON_CLOSE" called?

    Thank you for the answer, I'm glad you weren't all "UR A NUB LOL" on me. I have a question, though. I wish to code my very own JOptionPane named SOptionPane exclusively for the software. The reason for this is that the dialogs will be more customized. How do I use the static final ints, though? Declaring them is easy as pie, of course. But how would you tackle this situation? If you use the static final int "SAVE_IGNORE_CANCEL", how would you receive the input with "if(response == SOptionPane.SAVE_OPTION)" if the user chose "SAVE", for an example?

    By the way, my dad greets you all!

    EDIT:

    Would you create a JButton with an ActionListener and then assign the static final int to it?

    *WARNING: BADASS ASCII TEXT ART INCOMING*

    [ Save progress?
    [
    [
    [ [Save] [Don't save] [Cancel]
    [__________________________]

    I would assign the static final int SOptionPane.SAVE_OPTION to the Save button and check if it was selected through an if statement as showed above. If it would be true, run the code. What do you think? Judging by the humans key instinct to review a person by the first impression, I think you're more than qualified to answer this question. Thanks man.

  5. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,630
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: What is the "JFrame.EXIT_ON_CLOSE" called?

    You would have something like:
    public static final int SAVE_IGNORE_CANCEL = 0;
    public static final int SAVE_OPTION = 1;
    public static final int IGNORE_OPTION = 2;
    public static final int CANCEL_OPTION = 3;

    Personally, I think the pattern of using constants where enums could be used is poor behavior, but the current Java Swing framework seems to using constants, so you should probably do it with constants if you are extending the JOptionPane. If you are actually extending the JOptionPane class (meaning you are inheriting from it), make sure you are careful you are not using some integer values which will conflict with already existing framework.

    As far as implementing goes, I'm not entirely sure. As far as I can tell, you need to figure out how to make sure the method which created the SOptionPane does not return a value until one of the buttons is pressed. I think there is a way to make it wait for user input (you don't want to do endless loops or anything, it is extremely bad practice), but I can't think of how right now. It probably wouldn't hurt to try to find the code for JOptionPane and see how it currently works.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  6. The Following User Says Thank You to aussiemcgr For This Useful Post:

    Cronus (July 16th, 2013)

  7. #5
    Member Cronus's Avatar
    Join Date
    Feb 2013
    Location
    Gothenburg, Sweden
    Posts
    41
    My Mood
    Inspired
    Thanks
    6
    Thanked 7 Times in 6 Posts

    Default Re: What is the "JFrame.EXIT_ON_CLOSE" called?

    You helped me a lot! I'll check out the JOptionPane code and then I'll hopefully figure out the remaining process all by myself. Again, thank you.

Similar Threads

  1. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  2. How to put in a "new" image in ImageIcon JFrame ?
    By craigjlner in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 29th, 2013, 03:17 PM
  3. What's the difference between "import.javax.swing*" and JFrame inheritance
    By Johnny Bravo in forum Object Oriented Programming
    Replies: 5
    Last Post: August 14th, 2012, 09:28 AM
  4. Replies: 3
    Last Post: December 7th, 2011, 01:03 AM
  5. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM