I have written a launcher that prompts the user for their name then starts the game when they hit enter. The launcher looks like this:enter image description here

But when the user hits enter, this happens:enter image description here

The launcher stays open.

This is the relevant code in the launcher class:

    public void actionPerformed(ActionEvent evt) {
        String text = textField.getText();
        Game game = new Game();

    public void Launch() {
        //Create and set up the window.

        JFrame frame = new JFrame("Login");
     // maximize the jframe here
        //Add contents to the window.
        frame.add(new Launcher());
        //Display the window.

And this is for the main method in the game:

    public static void main(String[] argv) {
        Launcher launcher = new Launcher();

So how would I go about closing the launcher when the user has no use for it?

I am using a JFrame for the launcher and Lwjgl for the actual game window.

  • \$\begingroup\$ I've edited your question to remove the irrelevant code. When you include all your code, it looks like you don't have any idea what you're doing and clutters the question. For example, in a problem like this, we can assume that you have all the required include statements, there's no need to include them, same goes for your rendering code. \$\endgroup\$
    – House
    Mar 8, 2013 at 15:28

1 Answer 1


You want to think more about what your actual problem is. Always try to boil down these larger issues into smaller bits. In this case, your JFrame is staying open. That's expected behavior, since you haven't tried to close it!

So the problem isn't that your JFrame is staying open, it's that you don't even try to close it. Check out this question on SO for programmatically closing a JFrame.

  • 1
    \$\begingroup\$ So would I add frame.dispose(); after game.start(text); \$\endgroup\$
    – user25855
    Mar 8, 2013 at 15:31
  • \$\begingroup\$ Griffy, best way to find out is to try! I'm trying to be less direct in my answers to you, I want you to learn how to find help yourself first since it's an important skill for you to learn. Good luck with your game! \$\endgroup\$
    – House
    Mar 8, 2013 at 15:32
  • \$\begingroup\$ I can't get anything to work! :( \$\endgroup\$
    – user25855
    Mar 8, 2013 at 16:16
  • \$\begingroup\$ You'll need to be specific about what you've tried and what exactly isn't working. Take it one step at a time, try the most basic approach first and then build up from there once it's working. \$\endgroup\$
    – House
    Mar 8, 2013 at 16:33

You must log in to answer this question.