1

I have a server/client app. When the system is started a login window pops out. When Connect clicked - another JFrame (the Game frame) pops out. What I want is: when the 'X' on the Game frame is clicked - the game, for the current user, to be stopped and the login window to pop-out back again.

In short - when 'X' is clicked - terminate current process, close the window and pop-out the previous window. What is left is just to implement the 'windowClosing()' method, but I don't have a clue how. Here's what I have:

    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Toolkit;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JFrame;

    public class GameplayFrame extends JFrame {

    private GECanvas canvas;

    public GameplayFrame() {
        super("BattleCity");
        canvas = new GECanvas();
        getContentPane().setLayout(new BorderLayout());
        canvas.setPreferredSize(new Dimension(600, 600));
        getContentPane().add(canvas, BorderLayout.CENTER);
        setResizable(false);
        pack();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int x = (dim.width - getSize().width) / 2;
        int y = (dim.height - getSize().height) / 2;
        setLocation(x, y);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowListener(new NaBabaMiShortite());
    }

    private class NaBabaMiShortite extends WindowAdapter {

        @Override
        public void windowClosing(WindowEvent e) {

                // TO-DO
        }
    }

    public GECanvas getCanvas() {
        return canvas;
    }
}
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Milkncookiez
  • 6,817
  • 10
  • 57
  • 96

1 Answers1

1

Don't terminate the process. Simply call setVisible() on the two windows to make them visible or hide them as necessary.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • But I want to terminate the process. I made the following: ' @Override public void windowClosing(WindowEvent e) { setDefaultCloseOperation(EXIT_ON_CLOSE); loginWindow = new LoginWindow(); loginWindow.setVisible(true); } ' – Milkncookiez Jun 01 '12 at 10:52
  • If you terminate the process, who is going to open the window again? – Aaron Digulla Jun 01 '12 at 11:35