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) better would be implements CardLayout, as create
Top-Level Containerfor newWindow, then you’ll only to switch betweens Cards2) don’t create lots of
Top-Level Containeron 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)andsetVisible(true)JWindowmissed methods for settingsetDefaultCloseOperation(Whatever);3) if you’ll create constructor public JWindow(Frame owner), then you’ll call directly
SwingUtilities.getAccessibleChildrenCount() and SwingUtilities.getWindowAncestor()