-3

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();
 }

}
AJ.
  • 4,526
  • 5
  • 29
  • 41
  • 2
    Formatting issues aside, I find this question unclear. What does your code currently do and what particular part do you need help with? – PakkuDon Mar 12 '14 at 10:18
  • my code displays two buttons on the screen(an exit button and continue button).If you select the exit buttom you exit the program,if you select continue you proceed to another panel in the same window where you select your team.In this window you can select to go back to the first window or proceed to the game – Andrew Blem Mar 12 '14 at 12:05

1 Answers1

2

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

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • You really like CardLayout :D For reference, is there any objective arguments against consecutive JFrames? I'm aware they stack on the taskbar. – Gorbles Mar 12 '14 at 12:41
  • @Gorb _"Objective"_ I don't know. But I just think CardLayout is easier to maintain and is a cleaner approach. – Paul Samsotha Mar 12 '14 at 12:57
  • I find it better to encapsulate different objects or tools within their own frames, but I definitely see where you're coming from - especially for something as simple as a game startup process. Thanks for the reply! :) – Gorbles Mar 12 '14 at 13:03