Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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();
        System.out.println(text);
        entered=true;
        Game game = new Game();
        game.start(text);
    }

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

        JFrame frame = new JFrame("Login");
     // maximize the jframe here
        frame.setSize(800,600);
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //Add contents to the window.
        frame.add(new Launcher());
        //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.

share|improve this question
    
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. –  Byte56 Mar 8 '13 at 15:28
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
1  
So would I add frame.dispose(); after game.start(text); –  griffy100 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! –  Byte56 Mar 8 '13 at 15:32
    
Ok and Thanks for the luck. –  griffy100 Mar 8 '13 at 15:38
    
I can't get anything to work! :( –  griffy100 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. –  Byte56 Mar 8 '13 at 16:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.