Wednesday, June 22, 2022
HomeGame Developmentjava - Am i able to get the debuuging conclusion

java – Am i able to get the debuuging conclusion


bundle com.feedingfrenzy.view;

import java.awt.CardLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import com.feedingfrenzy.controller.GameManager;

public class MainMenuPanel extends MenuPanel {

// BUTTONS
personal JButton startNewGameButton;
personal JButton highScoresButton;
personal JButton helpButton;
personal JButton settingsButton;
personal JButton aboutButton;
personal JButton creditsButton;
personal JButton exitButton;
personal GameManager gameManager;
personal GamePanel gamePanel;

public MainMenuPanel(CardLayout cardLayout, JPanel cardPanel, GameManager gameManager, GamePanel gamePanel) {
    tremendous(cardLayout, cardPanel);
    this.gameManager = gameManager;
    this.gamePanel = gamePanel;
    attempt {
        backGroundImage = ImageIO.learn(getClass().getResource("/backgrounds/main_menu_background.jpg"));
    } catch (IOException e) {
        e.printStackTrace();
    }

    // Set GridBagLayout and constrains
    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 0, 150, 50 };
    gridBagLayout.rowHeights = new int[] { 0, 65, 65, 65, 65, 65, 65, 65, 0, 0 };
    gridBagLayout.columnWeights = new double[] { 1.0, 0.0 };
    gridBagLayout.rowWeights = new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE };
    setLayout(gridBagLayout);

    startNewGameButton = new JButton("New Recreation");
    GridBagConstraints gbc_newGameButton = new GridBagConstraints();
    gbc_newGameButton.fill = GridBagConstraints.BOTH;
    gbc_newGameButton.insets = new Insets(0, 0, 15, 0);
    gbc_newGameButton.gridx = 1;
    gbc_newGameButton.gridy = 1;
    add(startNewGameButton, gbc_newGameButton);

    highScoresButton = new JButton("Excessive Scores");
    GridBagConstraints gbc_highScoresButton = new GridBagConstraints();
    gbc_highScoresButton.fill = GridBagConstraints.BOTH;
    gbc_highScoresButton.insets = new Insets(0, 0, 15, 0);
    gbc_highScoresButton.gridx = 1;
    gbc_highScoresButton.gridy = 2;
    add(highScoresButton, gbc_highScoresButton);

    helpButton = new JButton("Assist");
    GridBagConstraints gbc_helpButton = new GridBagConstraints();
    gbc_helpButton.fill = GridBagConstraints.BOTH;
    gbc_helpButton.insets = new Insets(0, 0, 15, 0);
    gbc_helpButton.gridx = 1;
    gbc_helpButton.gridy = 3;
    add(helpButton, gbc_helpButton);

    settingsButton = new JButton("Settings");
    GridBagConstraints gbc_settingsButton = new GridBagConstraints();
    gbc_settingsButton.fill = GridBagConstraints.BOTH;
    gbc_settingsButton.insets = new Insets(0, 0, 15, 0);
    gbc_settingsButton.gridx = 1;
    gbc_settingsButton.gridy = 4;
    add(settingsButton, gbc_settingsButton);

    aboutButton = new JButton("About");
    GridBagConstraints gbc_aboutButton = new GridBagConstraints();
    gbc_aboutButton.fill = GridBagConstraints.BOTH;
    gbc_aboutButton.insets = new Insets(0, 0, 15, 0);
    gbc_aboutButton.gridx = 1;
    gbc_aboutButton.gridy = 5;
    add(aboutButton, gbc_aboutButton);

    creditsButton = new JButton("Credit");
    GridBagConstraints gbc_creditsButton = new GridBagConstraints();
    gbc_creditsButton.fill = GridBagConstraints.BOTH;
    gbc_creditsButton.insets = new Insets(0, 0, 15, 0);
    gbc_creditsButton.gridx = 1;
    gbc_creditsButton.gridy = 6;
    add(creditsButton, gbc_creditsButton);

    exitButton = new JButton("Exit");
    GridBagConstraints gbc_exitButton = new GridBagConstraints();
    gbc_exitButton.fill = GridBagConstraints.BOTH;
    gbc_exitButton.insets = new Insets(0, 0, 15, 0);
    gbc_exitButton.gridx = 1;
    gbc_exitButton.gridy = 7;
    add(exitButton, gbc_exitButton);

    setActionListeners();
}

personal void setActionListeners() {
    startNewGameButton.addActionListener(ae -> {
        cardLayout.present(parentPanel, GamePanel.class.getName());
        gameManager.startGame(true);
    });
    highScoresButton.addActionListener(ae -> {
        cardLayout.present(parentPanel, HighScorePanel.class.getName());
    });
    helpButton.addActionListener(ae -> {
        cardLayout.present(parentPanel, HelpPanel.class.getName());
    });
    settingsButton.addActionListener(ae -> {
        cardLayout.present(parentPanel, ChangeSettingsPanel.class.getName());
    });
    aboutButton.addActionListener(ae -> {
        cardLayout.present(parentPanel, AboutPanel.class.getName());
    });
    creditsButton.addActionListener(ae -> {
        cardLayout.present(parentPanel, CreditsPanel.class.getName());
    });
    exitButton.addActionListener(ae -> {
        int outcome = JOptionPane.showConfirmDialog(MainMenuPanel.this, "Are you certain you need to exit?",
                "Exit Recreation?", JOptionPane.YES_NO_OPTION);
        if (outcome == JOptionPane.YES_OPTION) {
            System.exit(0);
        }
    });
}

}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments