# JFrame launcher stays open when I'm finished with it

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:

But when the user hits enter, this happens:

The launcher stays open.

This is the relevant code in the launcher class:

    public void actionPerformed(ActionEvent evt) {
String text = textField.getText();
System.out.println(text);
entered=true;
Game game = new Game();
game.start(text);
}

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

// maximize the jframe here
frame.setSize(800,600);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Display the window.
frame.pack();
frame.setVisible(true);
while(entered==true){}
}


And this is for the main method in the game:

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


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.

• 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.
– House
Mar 8 '13 at 15:28

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.

• So would I add frame.dispose(); after game.start(text);
– user25855
Mar 8 '13 at 15:31
• 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!
– House
Mar 8 '13 at 15:32
• I can't get anything to work! :(
– user25855
Mar 8 '13 at 16:16
• 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.
– House
Mar 8 '13 at 16:33