From 8bbad65768b6c487421bcc043329efd6eb29c844 Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 22:08:44 +0100 Subject: [PATCH] Add Main Menu --- src/main/java/TicTacToe/TicTacToeGame.java | 2 +- src/main/java/hauptmenue/GameWindow.java | 86 ++++++++++++++++++++-- 2 files changed, 80 insertions(+), 8 deletions(-) diff --git a/src/main/java/TicTacToe/TicTacToeGame.java b/src/main/java/TicTacToe/TicTacToeGame.java index 642f6e5..33a8ee0 100644 --- a/src/main/java/TicTacToe/TicTacToeGame.java +++ b/src/main/java/TicTacToe/TicTacToeGame.java @@ -13,7 +13,7 @@ import javax.swing.JPanel; public class TicTacToeGame extends JPanel { private static final long serialVersionUID = 1L; - private static final int width = 600, height = 600; + public static final int width = 600, height = 600; private static final int maxPlayers = 3; private static final int playFieldSize = 9; diff --git a/src/main/java/hauptmenue/GameWindow.java b/src/main/java/hauptmenue/GameWindow.java index 9230044..6972a9e 100644 --- a/src/main/java/hauptmenue/GameWindow.java +++ b/src/main/java/hauptmenue/GameWindow.java @@ -1,28 +1,100 @@ package hauptmenue; import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import javax.swing.JButton; import javax.swing.JFrame; +import Minesweeper.MinesweeperGame; +import TicTacToe.TicTacToeGame; import solitaer.SolitaerGamePanel; import solitaer.SolitaerMenue; public class GameWindow extends JFrame { private static final long serialVersionUID = 1L; - private final SolitaerGamePanel gamePanel = new SolitaerGamePanel(); - - private SolitaerMenue smenue = new SolitaerMenue(gamePanel); public GameWindow() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - gamePanel.setPreferredSize(new Dimension(1180, 780)); - this.setJMenuBar(smenue.getMenue()); + setSize(new Dimension(200, 125)); + setLayout(null); - add(gamePanel); - pack(); + + + JButton soli = new JButton("Solitaer"); + JButton Tic = new JButton("TicTacToe"); + JButton Mine = new JButton("Minesweeper"); + + soli.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + soli.setVisible(false); + Tic.setVisible(false); + Mine.setVisible(false); + initSoli(); + } + }); + + Tic.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + soli.setVisible(false); + Tic.setVisible(false); + Mine.setVisible(false); + initTicTacToe(); + } + + }); + + Mine.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + soli.setVisible(false); + Tic.setVisible(false); + Mine.setVisible(false); + initMinesweeper(); + } + + + }); + soli.setBounds(0, 0, 200, 30); + Tic.setBounds(0, 30, 200, 30); + Mine.setBounds(0, 60, 200, 30); + add(soli); + add(Tic); + add(Mine); setVisible(true); } + private void initSoli() { + SolitaerGamePanel gamePanel = new SolitaerGamePanel(); + SolitaerMenue smenue = new SolitaerMenue(gamePanel); + gamePanel.setVisible(true); + gamePanel.setSize(new Dimension(1180, 780)); + setSize(new Dimension(1180, 780)); + //gamePanel.setPreferredSize(new Dimension(1180, 780)); + setJMenuBar(smenue.getMenue()); + add(gamePanel); + repaint(); + } + + public void initTicTacToe() { + TicTacToeGame ttt = new TicTacToeGame(); + setSize(ttt.width, ttt.height); + setLayout(null); + add(ttt); + } + + public void initMinesweeper() { + MinesweeperGame MsG = new MinesweeperGame(8,10); + setSize(MsG.WIDTH, MsG.HEIGTH); + setLayout(null); + add(MsG); + } + }