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 4 of 4

Thread: Terminating JFrame after a certain event.

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    41
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Terminating JFrame after a certain event.

    Hi, in my game I added a new "board" whcih starts the game. However once I finish the game, I have a boolean varaible and I set it to true. How can I use that variable to dispose of the Jframe I was using?

    I am doing something like this, however it is not working. Is there a better way than doing this? Like terminating the Thread it self?
    final static Runnable game_main = new Runnable() {

    public void run() {
    JFrame baseLevel = new JFrame("Half Life 3 - Episode 1");
    ImageIcon img = new ImageIcon("Pictures/Half-Life.png");
    // Base Level

    baseLevel.add(new Board());
    baseLevel.setSize((HEIGHT - 3) * SCALE, WIDTH * SCALE);
    baseLevel.setIconImage(img.getImage());
    baseLevel.setLocationRelativeTo(null);
    baseLevel.setVisible(true);
    baseLevel.setResizable(false);

    if(Board.game_end == true){
    try {
    Thread.sleep(1500);
    } catch (Exception e) {
    e.getMessage();
    }

    baseLevel.dispose();

    }

    }
    };


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Terminating JFrame after a certain event.

    Define "not working." Are you getting errors, nothing's happening, what? Post the details.

  3. #3
    Member
    Join Date
    Sep 2013
    Posts
    41
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Terminating JFrame after a certain event.

    I get no errors, the programm keeps functioning normally

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Terminating JFrame after a certain event.

    You might find this article helpful, but also search on "exit swing application".

    There's no reason to compare a boolean to true or false to return a boolean as in:

    // result is a boolean
    if ( result == true )

    Simply use:
    if ( result )

Similar Threads

  1. why is my while loop terminating?
    By frodooftheshire in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 15th, 2013, 05:58 PM
  2. How to fire off an event that closes another JFrame.
    By mstabosz in forum AWT / Java Swing
    Replies: 5
    Last Post: September 19th, 2013, 10:20 AM
  3. need help on jframe buttonclicked event
    By Eatiem0on in forum AWT / Java Swing
    Replies: 2
    Last Post: August 5th, 2013, 10:57 AM
  4. JFrame in event despatch thread
    By DanielJamesCollier in forum Java Theory & Questions
    Replies: 1
    Last Post: April 25th, 2012, 11:56 AM
  5. why the while loop is not terminating? plz help me out in this..
    By ab7 in forum Loops & Control Statements
    Replies: 3
    Last Post: December 30th, 2011, 01:48 AM