Skip to content
Snippets Groups Projects
Commit cc765450 authored by Ahmed Loui Al Koasmh's avatar Ahmed Loui Al Koasmh
Browse files

Added main menu display doxygen comments and general comments

parent 199ef619
No related branches found
No related tags found
No related merge requests found
......@@ -2,61 +2,79 @@ import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import javax.swing.ImageIcon;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
/**
* @brief A class that displays the Main Menu upon opening the application.
* @details The main menu allows the user to move to start a new game, see settings, and view
* high scores.
*/
public class MainMenuDisplay extends JFrame {
private static final long serialVersionUID = 1L; //!< Version number for serializable class
private JPanel contentPane; //!< Contain all the main menu UI components
/**
* @brief Creates the main menu JFrame
* @details Contains the logic that allows the user to interact with the sustem
*/
public MainMenuDisplay() {
// Define the properties for the JFrame
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setBackground(Color.BLACK);
setForeground(Color.BLACK);
setTitle("Snake Revamped");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 900, 600);
contentPane = new JPanel();
// Define the properties for JPanel the frame will be set to for the main menu.
contentPane = new JPanel(); //!< JPanel for the Main Menu
contentPane.setBackground(Color.BLACK);
contentPane.setForeground(Color.BLACK);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
// move window to middle of scren
// Move the window to middle of screen
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((int) ((dimension.getWidth() - getWidth()) / 2), (int) ((dimension.getHeight() - getHeight()) / 2));
// Define the button which allows the user to play a new game.
JButton btnPlayNewGame = new JButton("Play New Game");
btnPlayNewGame.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
// Define a blank white JPanel
JPanel gamePane = new JPanel();
JPanel gamePane = new JPanel(); //!< JPanel for the game
setContentPane(gamePane);
gamePane.setBackground(Color.WHITE);
// Add a new game to the content pane
// Define and add a new game JPanel to the content pane
GameDisplay newGame = new GameDisplay();
setLayout(new BorderLayout());
getContentPane().add(newGame);
setSize(700, 700);
setSize(700,700);
// Request focus so that keyboard inputs work
newGame.requestFocusInWindow();
......@@ -64,152 +82,152 @@ public class MainMenuDisplay extends JFrame {
validate();
// Start a new thread to recognize when end game screen is needed
Thread endGameView = new Thread() {
Thread endGameView = new Thread(){
public void run() {
while (!GameDisplay.gameOver) {
public void run(){
while(!GameDisplay.gameOver) {
System.out.checkError(); // Do not delete this line
}
// Remove the game contentPane when it ends.
getContentPane().removeAll();
EndGameDisplay EndGame = new EndGameDisplay();
// Define and add a new End game JPanel to the content pane
EndGameDisplay EndGame = new EndGameDisplay(); //!< JPanel for the End Game display
setContentPane(EndGame);
setSize(900, 600);
setSize(900,600);
// Set back the conditional values to false for upcoming iterations.
GameDisplay.gameOver = false;
GameDisplay.backClicked = false;
Thread transition = new Thread() {
public void run() {
while (!EndGameDisplay.goMenu && !EndGameDisplay.playAgain) {
System.out.checkError(); // Do not delete this line
/*Create a new thread that waits for the user's selection
* for the End Game JPanel screen.
* */
Thread transition = new Thread(){
public void run(){
// Wait for the user's choice
while(!EndGameDisplay.goMenu && !EndGameDisplay.playAgain) {
System.out.checkError(); // Do not delete this line
}
// Remove the end game JPanel when selection is made
getContentPane().removeAll();
// Switch the user's choice of the main menu
if (EndGameDisplay.goMenu) {
EndGameDisplay.goMenu = false;
setContentPane(contentPane);
contentPane.setLayout(null);
}
// Switch the user's choice of starting a new game
else if (EndGameDisplay.playAgain) {
EndGameDisplay.playAgain = false;
// Switch to the main menu and programtically start a new game.
setContentPane(contentPane);
MouseEvent click;
Point point;
long time;
point = new Point(arg0.getX(), arg0.getY());
point = new Point(arg0.getX(),arg0.getY());
SwingUtilities.convertPointToScreen(point, btnPlayNewGame);
time = System.currentTimeMillis();
click = new MouseEvent(btnPlayNewGame, MouseEvent.MOUSE_CLICKED, time, 0,
arg0.getX(), arg0.getY(), point.x, point.y, 1, false, MouseEvent.BUTTON1);
time = System.currentTimeMillis();
click = new MouseEvent(btnPlayNewGame, MouseEvent.MOUSE_CLICKED, time, 0, arg0.getX(),arg0.getY(), point.x, point.y, 1, false, MouseEvent.BUTTON1);
btnPlayNewGame.dispatchEvent(click);
}
}
}
};
transition.start();
}
transition.start(); // Start transition to new game or main menu
}
};
endGameView.start();
endGameView.start(); // Start viewing of the end game screen
}
});
// btnPlayNewGame.setFont(new Font("Tahoma", Font.PLAIN, 27));
// Define the properties for the Play New Game button
btnPlayNewGame.setBounds(326, 218, 246, 89);
contentPane.add(btnPlayNewGame);
btnPlayNewGame.setFont(new Font("TimesRoman", Font.PLAIN, 27));
btnPlayNewGame.setBackground(new Color(145, 139, 139));
btnPlayNewGame.setBackground(new Color(145,139,139));
btnPlayNewGame.setForeground(Color.WHITE);
btnPlayNewGame.setFocusPainted(false);
// Define the "View High Scores" button and it's properties
JButton btnViewHighScores = new JButton("View High Scores");
btnViewHighScores.setFont(new Font("TimesRoman", Font.PLAIN, 24));
btnViewHighScores.setBackground(new Color(145, 139, 139));
btnViewHighScores.setBackground(new Color(145,139,139));
btnViewHighScores.setForeground(Color.WHITE);
btnViewHighScores.setFocusPainted(false);
// Recieve the user's mouse click input when the high scores button is selected.
btnViewHighScores.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// Switch to and define the properties for the score display screen
setVisible(false);
ScoreDisplay panel = new ScoreDisplay();
panel.setSize(900, 600);
ScoreDisplay panel = new ScoreDisplay(); //!< JPanel for the High Scores Display
panel.setSize(900,600);
panel.setVisible(true);
Thread check = new Thread() {
public void run() {
while (!ScoreDisplay.goMenu) {
System.out.checkError(); // Do not remove
/*Define a new thread that wait's for the user's input to return to the
* main menu screen.
* */
Thread check = new Thread(){
public void run(){
while(!ScoreDisplay.goMenu) {
System.out.checkError(); //Do not remove
}
ScoreDisplay.goMenu = false;
panel.setVisible(false);
setVisible(true);
}
}
};
check.start();
check.start(); // Start the high scores thread
}
});
btnViewHighScores.setBounds(326, 346, 246, 89);
contentPane.add(btnViewHighScores);
// Add the Main Menu game name to the middle of the screen and define properties
JLabel lblSnakeRevamped = new JLabel("Snake Revamped");
lblSnakeRevamped.setForeground(new Color(80, 125, 124));
lblSnakeRevamped.setFont(new Font("TimesRoman", Font.PLAIN, 66));
lblSnakeRevamped.setBounds(228, 98, 558, 118);
contentPane.add(lblSnakeRevamped);
contentPane.setBackground(new Color(236, 226, 225));
/*
* JLabel lblDecorationOne = new JLabel(""); lblDecorationOne.setIcon(new
* ImageIcon("snakeIcon.jpg")); lblDecorationOne.setBounds(0, 0, 1000, 1000);
* contentPane.add(lblDecorationOne); // JLabel lblDecorationOne = new
* JLabel(""); // lblDecorationOne.setIcon(new ImageIcon("snakeIcon.jpg")); //
* lblDecorationOne.setBounds(67, 116, 259, 471); //
* contentPane.add(lblDecorationOne); // /* JLabel lblDecorationTwo = new
* JLabel(""); lblDecorationTwo.setFont(new Font("TimesRoman", Font.PLAIN, 24));
* lblDecorationTwo.setIcon(new ImageIcon("snakeIcon.jpg"));
* lblDecorationTwo.setBounds(106, -18, 680, 113);
* contentPane.add(lblDecorationTwo);
*/
// JLabel lblDecorationThree = new JLabel("");
// lblDecorationThree.setIcon(new ImageIcon("snakeIcon.jpg"));
// lblDecorationThree.setBounds(379, 206, 495, 290);
// contentPane.add(lblDecorationThree);
//
// JLabel lblNewLabel_1 = new JLabel("");
// lblNewLabel_1.setIcon(new ImageIcon("snakeIcon.jpg"));
// lblNewLabel_1.setBounds(116, 331, 574, 284);
// contentPane.add(lblNewLabel_1);
// setLayout(new BorderLayout());
// setLayout(new FlowLayout());
// background.setLayout(new FlowLayout());
contentPane.setBackground(new Color(236,226,225));
// Define the "Settings" button and it's properties
JButton btnNewButton = new JButton("Settings");
btnNewButton.setFont(new Font("TimesRoman", Font.PLAIN, 20));
btnNewButton.setBackground(new Color(145, 139, 139));
btnNewButton.setBackground(new Color(145,139,139));
btnNewButton.setForeground(Color.WHITE);
btnNewButton.setFocusPainted(false);
// Recieve the user's mouse click input when the settings button is selected.
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
SettingDisplay panel = new SettingDisplay();
;
// Define the settings JPanel and add it to the main JFrame
SettingDisplay panel = new SettingDisplay(); //!< JPanel for the Settings display
pack();
MainMenuDisplay.this.setSize(900, 600);
MainMenuDisplay.this.setSize(900,600);
setContentPane(panel);
// Start a new thread that wait's for the user to save their settings choices.
Thread settingWait = new Thread() {
public void run() {
while (!panel.settingsSaved) {
// Wait for the user to save their choices.
while(!panel.settingsSaved) {
System.out.checkError(); // Do not delete
}
panel.settingsSaved = false;
// Return to the main menu
pack();
MainMenuDisplay.this.setSize(900, 600);
MainMenuDisplay.this.setSize(900,600);
setContentPane(contentPane);
}
};
......@@ -219,23 +237,25 @@ public class MainMenuDisplay extends JFrame {
btnNewButton.setBounds(692, 21, 128, 44);
contentPane.add(btnNewButton);
// Define the "Instructions" button and it's properties
JButton btnInstructions = new JButton("Instructions");
btnInstructions.setFont(new Font("TimesRoman", Font.PLAIN, 20));
btnInstructions.setBackground(new Color(145, 139, 139));
btnInstructions.setBackground(new Color(145,139,139));
btnInstructions.setForeground(Color.WHITE);
btnInstructions.setFocusPainted(false);
// Recieve the user's mouse click input when the instructions button is selected.
btnInstructions.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
InstructionsDisplay panel = new InstructionsDisplay();
InstructionsDisplay panel = new InstructionsDisplay(); //!< JPanel for the instructions display
panel.setVisible(true);
}
});
btnInstructions.setBounds(40, 21, 138, 44);
contentPane.add(btnInstructions);
// Define the background of the main menu
JLabel newImage = new JLabel(new ImageIcon("MainMenuBackground.png"));
contentPane.add(newImage);
newImage.setBounds(-100, 0, 1300, 600);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment