From 713f6b19c8e4232c0543ea50ac0bf185971a118b Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Sat, 22 Jan 2022 17:54:02 +0100 Subject: [PATCH] gameexplorer_gui: added actionListener for logout button --- .../de/tims/gameexplorer/GameExplorer.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java index 07915d1..f78f205 100644 --- a/src/main/java/de/tims/gameexplorer/GameExplorer.java +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -44,7 +44,7 @@ public class GameExplorer { private Dimension smallBtnSize; private GridBagConstraints gbc; - private static final String playerFile = "src/main/java/resources/player_data.csv"; + private static final String PLAYER_FILE = "src/main/java/resources/player_data.csv"; private enum Game { FLEETSTORM, FOURWINS, TICTACTOE, LEADERBOARD }; private Game actualGame; @@ -94,6 +94,7 @@ public class GameExplorer { leaderboardBtn.addActionListener(new GameAction()); logoutBtn = new JButton("Logout"); logoutBtn.setPreferredSize(smallBtnSize); + logoutBtn.addActionListener(new LogoutAction()); exitBtn = new JButton("Exit"); exitBtn.setPreferredSize(smallBtnSize); @@ -278,9 +279,10 @@ public class GameExplorer { if (!userInput.equals("")) { loginWarning.setText(""); - manager.loadPlayers(playerFile); + manager.loadPlayers(PLAYER_FILE); actualPlayer = manager.selectPlayer(userInput); + frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.remove(loginPanel); frame.add(explorerPanel); frame.revalidate(); @@ -321,6 +323,21 @@ public class GameExplorer { } } + private class LogoutAction implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + manager.savePlayers(PLAYER_FILE); + + buildLoginPanel(); + + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.remove(explorerPanel); + frame.add(loginPanel); + frame.revalidate(); + frame.repaint(); + } + } + private class BackAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) {