From 85669e4412c5b2d0138a234a914a8640c223386e Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Mon, 27 Dec 2021 17:38:14 +0100 Subject: [PATCH] gameexplorer: each button opens a different (dummy) game panel --- .../de/tims/gameexplorer/GameExplorer.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java index cde21e3..03c23dd 100644 --- a/src/main/java/de/tims/gameexplorer/GameExplorer.java +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -10,6 +10,10 @@ public class GameExplorer { private JPanel explorerPanel; private JPanel gamePanel; private JPanel navigationPanel; + private JPanel fleetstormPanel; + private JPanel fourwinsPanel; + private JPanel tictactoePanel; + private JPanel leaderboardPanel; private JPanel border1; private JPanel border2; private JPanel border3; @@ -26,6 +30,9 @@ public class GameExplorer { private Dimension btnSize; private GridBagConstraints gbc; + private enum Game { FLEETSTORM, FOURWINS, TICTACTOE, LEADERBOARD }; + private Game actualGame; + public GameExplorer() { frame = new JFrame("1000 infomagische Spiele"); @@ -157,11 +164,43 @@ public class GameExplorer { gamePanel.setLayout(new BorderLayout()); gamePanel.add(navigationPanel, BorderLayout.PAGE_START); + + //use of dummy panels because real panels have not been implemented yet + fleetstormPanel = new JPanel(); + fleetstormPanel.setBackground(Color.BLUE); + + fourwinsPanel = new JPanel(); + fourwinsPanel.setBackground(Color.GREEN); + + tictactoePanel = new JPanel(); + tictactoePanel.setBackground(Color.YELLOW); + + leaderboardPanel = new JPanel(); + leaderboardPanel.setBackground(Color.RED); } private class GameAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { + //each button adds a different dummy panel to the gamePanel + if (e.getSource() == fleetstormBtn) { + actualGame = Game.FLEETSTORM; + chosenGame.setText("Schiffe versenken"); + gamePanel.add(fleetstormPanel, BorderLayout.CENTER); + } else if (e.getSource() == fourwinsBtn) { + actualGame = Game.FOURWINS; + chosenGame.setText("Vier gewinnt"); + gamePanel.add(fourwinsPanel, BorderLayout.CENTER); + } else if (e.getSource() == tictactoeBtn) { + actualGame = Game.TICTACTOE; + chosenGame.setText("TicTacToe"); + gamePanel.add(tictactoePanel, BorderLayout.CENTER); + } else if (e.getSource() == leaderboardBtn) { + actualGame = Game.LEADERBOARD; + chosenGame.setText("Leaderboard"); + gamePanel.add(leaderboardPanel, BorderLayout.CENTER); + } + frame.remove(explorerPanel); frame.add(gamePanel); frame.revalidate(); @@ -172,6 +211,20 @@ public class GameExplorer { private class BackAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { + switch (actualGame) { + case FLEETSTORM: + gamePanel.remove(fleetstormPanel); + break; + case FOURWINS: + gamePanel.remove(fourwinsPanel); + break; + case TICTACTOE: + gamePanel.remove(tictactoePanel); + break; + case LEADERBOARD: + gamePanel.remove(leaderboardPanel); + } + frame.remove(gamePanel); frame.add(explorerPanel); frame.revalidate();