From dfbd3cd79d9f3c5bc80971f38e948e8d84712f97 Mon Sep 17 00:00:00 2001 From: Ozan-Can Ekinci Date: Thu, 12 Jan 2023 18:23:18 +0100 Subject: [PATCH] added GridBagLayout and functionality for buttons after winning --- src/main/java/Gui/ActionHandler.java | 6 ++++++ src/main/java/Gui/GameGui.java | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/Gui/ActionHandler.java b/src/main/java/Gui/ActionHandler.java index 3f32cd8..9eca7bb 100644 --- a/src/main/java/Gui/ActionHandler.java +++ b/src/main/java/Gui/ActionHandler.java @@ -22,6 +22,12 @@ public class ActionHandler implements ActionListener { restartGame.startGame(); } + if (e.getSource() == GameGui.RestartBtn1) { + GameGui.questionNr = 0; + GameGui.WinningPanel.setVisible(false); + restartGame.startGame(); + } + } } diff --git a/src/main/java/Gui/GameGui.java b/src/main/java/Gui/GameGui.java index 9ce5fac..c88b72c 100644 --- a/src/main/java/Gui/GameGui.java +++ b/src/main/java/Gui/GameGui.java @@ -77,18 +77,23 @@ GridBagConstraints gbc; GameGui.MainPanel.setVisible(false); GameGui.ButtonPanel.setVisible(false); + GridBagConstraints gbc = new GridBagConstraints(); + RestartBtn1 = new JButton("Nochmal Spielen"); ClosingBtn = new JButton("Schliessen"); - WinningPanel = new JPanel(new GridLayout()); + WinningPanel = new JPanel(); + WinningPanel.setLayout(new GridBagLayout()); WinningLabel = new JLabel("Du hast Gewonnen!"); WinningLabel.setVerticalAlignment(JLabel.CENTER); WinningLabel.setHorizontalAlignment(JLabel.CENTER); WinningLabel.setFont(new Font("Serif", Font.BOLD, 28)); - WinningPanel.add(WinningLabel); - WinningPanel.add(RestartBtn1); - WinningPanel.add(ClosingBtn); + WinningPanel.add(WinningLabel,gbc); + WinningPanel.add(RestartBtn1,gbc); + WinningPanel.add(ClosingBtn,gbc); + RestartBtn1.addActionListener(new ActionHandler()); + ClosingBtn.addActionListener(new ActionHandler()); gui.Frame.add(WinningPanel); }