Beispiel #1
0
  /** Inits the buttons in the main menu and the options menu */
  public void mainMenuButtons() {
    btnGames =
        new Menu_Button(0) { // Games button gets the id=0
          public void press() { // This is what happens when the Games button
            // is pressed
            if (gamePanel != null && gamePanel.getPanels().length > 0) {
              cl.show(contentPane, "panel_1");
              previousPanel = mainMenu;
              currentPanel = gamePanel.getPanel(0); // Fetches the FIRST
              // game panel (id=0)
              mainMenu.hide();
              gamePanel.getPanel(0).show();
              nbrButtons = gamePanel.nbrGamesOnPanel(0); // Checks the
              // number of
              // buttons on
              // panel with
              // id=0
              controller.setSelectedNumber(0);
            } else {
              currentPanel = mainMenu;
              new MessagePopUp("No games found");
            }
          }
        };

    btnOptions =
        new Menu_Button(1) { // Options button gets the id=1
          public void press() { // This is what happens when the Options
            // button is pressed
            optionsMenuConnectedIP =
                "Connection data\n\nBase unit IP:\n"
                    + controller.getIPbaseunit()
                    + "\n\nNumber of connected\nhandunits: "
                    + controller.getNbrConnected();
            cl.show(contentPane, "panel_2");
            previousPanel = mainMenu;
            currentPanel = optionsMenu;
            mainMenu.hide();
            optionsMenu.show();
            nbrButtons = 2;
            controller.setSelectedNumber(0);
            taIP.setText(optionsMenuConnectedIP);
            controller.updateButtons(controller.getOptionMenuButtons());
          }
        };

    btnAbout =
        new Menu_Button(2) { // About button gets the id=2
          public void press() { // This is what happens when the About button
            // is pressed
            cl.show(contentPane, "panel_3");
            mainMenu.hide();
            previousPanel = mainMenu;
            aboutMenu.show();
            currentPanel = aboutMenu;
            nbrButtons = 1;
            contentPane.repaint();
            contentPane.revalidate();
            txtrAbout.setText(aboutText);
          }
        };

    // Adds the buttons to the arraylist of main menu buttons and options
    // buttons
    Main_Menu_Buttons.add(btnGames);
    Main_Menu_Buttons.add(btnAbout);
    Main_Menu_Buttons.add(btnOptions);
    // Main_Menu_Buttons.add(btnSound);

    btnGames.setBounds(748, 83, 165, 68);
    btnOptions.setBounds(748, 248, 165, 68);
    btnAbout.setBounds(748, 413, 165, 68);

    btnGames.setText("Games");
    btnOptions.setText("Options");
    btnAbout.setText("About");
    btnSound.setText("Sound");

    // Adds the buttons to the GUI
    mainMenu.add(btnGames);
    mainMenu.add(btnOptions);
    mainMenu.add(btnAbout);
  }
Beispiel #2
0
  /** Inits the GUI */
  public void initGui() {
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds(0, 0, resWidth, resHeight);
    // setBounds(0, 0, screenSize.width, screenSize.height);

    contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
    setContentPane(contentPane);
    cl = new CardLayout(0, 0);
    contentPane.setLayout(cl);

    contentPane.add(mainMenu, "name_6798406101994");
    mainMenu.setLayout(null);
    previousPanel = mainMenu;
    currentPanel = mainMenu;
    addGamePanels();

    /* ************************ Extra Exit button ********************* */
    // This extra exit button is only used during the development, for easy
    // shutdown of the program.
    // In the delivery version, there will be no exit button, because the
    // user should never be able
    // to return the operating system of the console.
    // JButton btnClose = new JButton("Exit");
    // btnClose.setBounds(100, 10, 165, 68);
    // mainMenu.add(btnClose);
    // btnClose.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // System.exit(0); // Yes, system.exit in the GUI - simply because this
    // is only a dev's button.
    // }
    // });
    /* *********************** end Extra Exit button******************* */

    /* *************************** Options Stuff ********************** */
    optionsMenu = new JPanel();
    contentPane.add(optionsMenu, "name_7946040729344");
    optionsMenu.setLayout(null);

    taSound.setFont(new Font("Tahoma", Font.PLAIN, 15));
    taSound.setBounds(748, 163 + 59 + 68 / 4, 165, 34);
    optionsMenu.add(taSound);

    taIP.setText(optionsMenuConnectedIP);
    taIP.setFont(new Font("Tahoma", Font.PLAIN, 15));
    taIP.setBounds(748, 210 + 59 + 68 / 4, 165, 234);
    optionsMenu.add(taIP);

    btnSound.setBounds(748, 83 + 59 + 68 / 4, 165, 68);
    this.controller.addOptionMenuButton(btnSound);
    optionsMenu.add(btnSound);
    btnSound.setText("Turn sound on/off");

    btnGetGameList.setBounds(748, 83, 165, 68);
    this.controller.addOptionMenuButton(btnGetGameList);
    optionsMenu.add(btnGetGameList);
    btnGetGameList.setText("Update game list");
    /* ************************ End options Stuff ********************* */

    /* ************************** "About" stuff *********************** */
    aboutMenu = new JPanel();
    contentPane.add(aboutMenu, "name_8765118079202");
    aboutMenu.setLayout(null);
    txtrAbout.setBounds(648, 210, 265, 234);
    aboutMenu.add(txtrAbout);
    /* *********************** End "About" stuff ********************** */
    mainMenuButtons();

    initBG(mainMenu, bgMain, "/bg1.jpg");
    initBG(optionsMenu, bgOptions, "/bg2.jpg");
    initBG(aboutMenu, bgAbout, "/bg2.jpg");
  }