Browse Source

gameexplorer: added action listeners for navigation between game and menu

gameexplorer
Tobias Krause 3 years ago
committed by Lorenz Hohmann
parent
commit
d2fb0fa2b3
  1. 28
      src/main/java/de/tims/gameexplorer/GameExplorer.java

28
src/main/java/de/tims/gameexplorer/GameExplorer.java

@ -1,6 +1,7 @@
package de.tims.gameexplorer; package de.tims.gameexplorer;
import java.awt.*; import java.awt.*;
import java.awt.event.*;
import javax.swing.*; import javax.swing.*;
public class GameExplorer { public class GameExplorer {
@ -36,7 +37,7 @@ public class GameExplorer {
buildNavigationPanel(); buildNavigationPanel();
buildGamePanels(); buildGamePanels();
frame.add(gamePanel);
frame.add(explorerPanel);
frame.setMinimumSize(minSize); frame.setMinimumSize(minSize);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -51,12 +52,16 @@ public class GameExplorer {
fleetstormBtn = new JButton("Schiffe versenken"); fleetstormBtn = new JButton("Schiffe versenken");
fleetstormBtn.setPreferredSize(btnSize); fleetstormBtn.setPreferredSize(btnSize);
fleetstormBtn.addActionListener(new GameAction());
fourwinsBtn = new JButton("Vier gewinnt"); fourwinsBtn = new JButton("Vier gewinnt");
fourwinsBtn.setPreferredSize(btnSize); fourwinsBtn.setPreferredSize(btnSize);
fourwinsBtn.addActionListener(new GameAction());
tictactoeBtn = new JButton("TicTacToe"); tictactoeBtn = new JButton("TicTacToe");
tictactoeBtn.setPreferredSize(btnSize); tictactoeBtn.setPreferredSize(btnSize);
tictactoeBtn.addActionListener(new GameAction());
leaderboardBtn = new JButton("Leaderboard"); leaderboardBtn = new JButton("Leaderboard");
leaderboardBtn.setPreferredSize(btnSize); leaderboardBtn.setPreferredSize(btnSize);
leaderboardBtn.addActionListener(new GameAction());
border1 = new JPanel(); border1 = new JPanel();
border1.setOpaque(false); border1.setOpaque(false);
@ -120,6 +125,7 @@ public class GameExplorer {
navigationPanel.setLayout(new GridBagLayout()); navigationPanel.setLayout(new GridBagLayout());
backBtn = new JButton("< Zurück"); backBtn = new JButton("< Zurück");
backBtn.addActionListener(new BackAction());
chosenGame = new JLabel(); chosenGame = new JLabel();
@ -153,6 +159,26 @@ public class GameExplorer {
gamePanel.add(navigationPanel, BorderLayout.PAGE_START); gamePanel.add(navigationPanel, BorderLayout.PAGE_START);
} }
private class GameAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
frame.remove(explorerPanel);
frame.add(gamePanel);
frame.revalidate();
frame.repaint();
}
}
private class BackAction implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
frame.remove(gamePanel);
frame.add(explorerPanel);
frame.revalidate();
frame.repaint();
}
}
public static void main(String[] args) { public static void main(String[] args) {
new GameExplorer(); new GameExplorer();
} }

Loading…
Cancel
Save