1

I'm trying to work on a project - we are creating a little game with a GUI. I decided to start by working on a 'main menu'. Essentially, there will be buttons such as "Single Player", "Help", etc...

I've made the GUI with the menu, etc. I have added listeners as well.

How do I approach the problem now? If someone clicks, say, 'Single Player', I'd like the screen to change to display a title showing "SINGLE PLAYER" and get rid of the main menu. What do I need to do in my actionPerformed() method to get this effect?

I guess I will be able to work it out from there.

Any help would be greatly appreciated.

2 Answers 2

3
Sign up to request clarification or add additional context in comments.

Comments

0

The best approach would be to put the corresponding windows onto a separate Jpanel and have one master panel in your gui. Whenever the user clicks on a button, you remove whatever was on the master panel add the corrseponding panel, then repaint the gui.

something like this:

    if (e.getSource() == button){           
                masterPanel.removeAll();            
                masterPanel.add(newWindow);                 
                this.setVisible(true);
                this.repaint();     
            }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.