Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6603291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:59:22+00:00 2026-05-25T18:59:22+00:00

How can i exit only they new MainGame that i created from Main? Where

  • 0

How can i exit only they new MainGame that i created from Main?
Where Main is having an original layer of game. And the MainGame was a dialog window (such as modal windows).

Main.java: (main code)

public class Main extends JWindow
{
  private static JWindow j;
  public static MainGame mp;

  public static void main(String[] args)
  {
        new Thread(new Runnable() 
        {
          public void run()
          {            
            mp = new MainGame(); 
            mp.runit();            
            //mp.stopit();
          }
        }).start();

        j = new Main();
        j.setVisible(true);             
  }
}

MainGame.java: (this was extended by Main, and i would like to quite this only).

public class MainGame extends JWindow 
{
  private static JWindow j;
  public MainGame()
  { 
    // some GUI ... 
  }

  public static void runit()
  {
    j = new MainGame();
    j.setVisible();

  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:59:22+00:00Added an answer on May 25, 2026 at 6:59 pm

    1) better would be implements CardLayout, as create Top-Level Container for new Window, then you’ll only to switch betweens Cards

    2) don’t create lots of Top-Level Container on Runtime, because there are still in JVM memory untill current instance exist,

    • create required number of and re-use that, to avoiding possible memory lacks

    • then you have to call setVisible(false) and setVisible(true)

    • JWindow missed methods for setting setDefaultCloseOperation(Whatever);

    3) if you’ll create constructor public JWindow(Frame owner), then you’ll call directly

    SwingUtilities.getAccessibleChildrenCount() and SwingUtilities.getWindowAncestor()

    import javax.swing.*;
    import java.awt.*;
    
    public class Testing {
    
        private JFrame f = new JFrame("Main Frame");
        private JWindow splashScreen = new JWindow();
    
        public Testing() {
            splashScreen = new JWindow(f);
            splashScreen.getContentPane().setLayout(new GridBagLayout());
            JLabel label = new JLabel("Splash Screen");
            label.setFont(label.getFont().deriveFont(96f));
            splashScreen.getContentPane().add(label, new GridBagConstraints());
            splashScreen.pack();
            splashScreen.setLocationRelativeTo(null);
            splashScreen.setVisible(true);
            new Thread(new Runnable() {
    
                @Override
                public void run() {
                    readDatabase();
                    SwingUtilities.invokeLater(new Runnable() {
    
                        @Override
                        public void run() {
                            createAndShowGUI();
                        }
                    });
                }
            }).start();
        }
    
        public void readDatabase() {
            //simulate time to read/load data - 10 seconds?
            try {
                Thread.sleep(2000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public void createAndShowGUI() {
            JLabel label = new JLabel("My Frame");
            label.setFont(label.getFont().deriveFont(96f));
            f.add(label);
            f.setLocationRelativeTo(null);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setVisible(true);
            System.out.println("JFrame getAccessibleChildrenCount count -> "
                    + SwingUtilities.getAccessibleChildrenCount(f));
            System.out.println("JWindow getParent -> "
                    + SwingUtilities.getWindowAncestor(splashScreen));
            splashScreen.dispose();
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    Testing t = new Testing();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know that in vb.net you can just do Exit Sub but i would
How can I start a job on a *nix system that will not exit
What are the default values that can be passed to Environment.Exit method and what
So the example from the wiki has phantom.exit() in two places here. Why can't
In vim, type :sh will switch to shell, and exit can exit the shell
Can anyone tell me? What is the difference between exit(0) and exit(1) in C
In c# you can return an integer to the underlying caller using Environment.Exit(n) (which
I want to know how and when can I use the exit() function like
This is my warning. implicit declaration of function 'exit' How i can remove it.
I'm using VBA to create a FileOpenDialog object so that the user can select

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.