How to create a game menu with 3 interfaces

How to create a game menu with three interfaces,1st interface has two option exit and continue,choose team and continue or back,3rd playing interface

    package SimpleSoccer;
import java.awt.Color; 
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton; 
import javax.swing.JFrame;
import javax.swing.JLabel; 
import javax.swing.JMenuBar;
import javax.swing.JPanel;

/**  *  * @author Andyblem  */ public class TopLevelDemo {

static JButton startButton = new JButton("START");
static JButton exitButton = new JButton("EXIT");
static JButton backButton = new JButton("MENU");
static JPanel panel = new JPanel(new FlowLayout());
static JFrame frame;
 private static void createAndShowGUI(){

    frame = new JFrame("Top Level Demo");
    frame.setSize(400,400);
    frame.setResizable(false);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar cyanMenuBar = new JMenuBar();
    cyanMenuBar.setOpaque(true);
    cyanMenuBar.setBackground(Color.cyan);
    cyanMenuBar.setPreferredSize(new Dimension(200,180));

    JLabel yellowLabel = new JLabel();
    yellowLabel.setOpaque(true);
    yellowLabel.setBackground(Color.yellow);
    yellowLabel.setPreferredSize(new Dimension(200,20));
    frame.setJMenuBar(cyanMenuBar);


    frame.getContentPane().add(panel);
    panel.add(startButton);
    panel.add(exitButton);
   // frame.getContentPane().add(exitButton);
    frame.pack();
    frame.setVisible(true);
 }

public static void main(String args[]){
    createAndShowGUI();
 }

}

Answers


Your "question" (if you could even call it that) is kind of unclear. Seems like you just don't know where to begin. So I'll give you a tip.

What I would do is:

  • Use a CardLayout. What the layout does is "layer" panels, making them navigable with methods like show(pickAPanelToShow), next(nextPanel), and previous(previousPanel).

  • What you can do is on first page have a the two buttons, if continue is pressed, then the next() method can take you to the chooseTeamPanel. And from that panel you can navigate to the gamePanel after the team is chosen.

You can see more at How to use CardLayout and you can see an example here


Need Your Help

Programmatically define global session timeout in Java EE/GlassFish/Spring

java-ee jboss session-timeout

I wanted to know if there's a way to programmatically define a session timeout in Java EE/GlassFish/Spring other than setting it in web.xml. I know that you can do it for one session by event.getSe...

DrawableCompat tinting does not work on pre-Lollipop

android drawable tint

I'm using the new TextInputLayout to wrap an EditText. When I determine a field has an error I do the following: