From 1f5aa08c7176d5e1cc458f83c9a45d7bd406a4c5 Mon Sep 17 00:00:00 2001 From: Ozan-Can Ekinci Date: Thu, 12 Jan 2023 17:14:52 +0100 Subject: [PATCH] refactoring: moved createRestartButton method to LosingPanel --- src/main/java/Gui/GameGui.java | 37 ++++++++++++------------ src/main/java/Gui/GameGuiInterface.java | 2 -- src/main/java/game/loadNextQuestion.java | 1 - 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/main/java/Gui/GameGui.java b/src/main/java/Gui/GameGui.java index bc8c125..64ba1c4 100644 --- a/src/main/java/Gui/GameGui.java +++ b/src/main/java/Gui/GameGui.java @@ -46,13 +46,29 @@ GridBagConstraints gbc; public void createLosingPanel() { MainPanel.setVisible(false); ButtonPanel.setVisible(false); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridwidth = GridBagConstraints.REMAINDER; + gbc.fill = GridBagConstraints.HORIZONTAL; + gbc.ipadx = 200; + gbc.ipady = 100; + gbc.insets = new Insets(20, 0, 0, 0); + + RestartBtn = new JButton("Neustarten"); + ClosingBtn = new JButton("Schliessen"); + LosingPanel = new JPanel(); LosingPanel.setLayout(new GridBagLayout()); LosingLabel = new JLabel("Du hast Verloren!"); LosingLabel.setVerticalAlignment(JLabel.CENTER); LosingLabel.setHorizontalAlignment(JLabel.CENTER); LosingLabel.setFont(new Font("Serif", Font.BOLD, 28)); - LosingPanel.add(LosingLabel); + + LosingPanel.add(LosingLabel,gbc); + LosingPanel.add(RestartBtn,gbc); + LosingPanel.add(ClosingBtn,gbc); + RestartBtn.addActionListener(new ActionHandler()); + ClosingBtn.addActionListener(new ActionHandler()); gui.Frame.add(LosingPanel); } @@ -128,22 +144,5 @@ GridBagConstraints gbc; MainPanel.add(ButtonPanel); } - @Override - public void createRestartButton() { - GridBagConstraints gbc = new GridBagConstraints(); - gbc.gridwidth = GridBagConstraints.REMAINDER; - gbc.fill = GridBagConstraints.HORIZONTAL; - gbc.ipadx = 200; - gbc.ipady = 100; - gbc.insets = new Insets(20, 0, 0, 0); - RestartBtn = new JButton("Neustarten"); - ClosingBtn = new JButton("Schliessen"); - - LosingPanel.add(LosingLabel,gbc); - LosingPanel.add(RestartBtn,gbc); - LosingPanel.add(ClosingBtn,gbc); - - RestartBtn.addActionListener(new ActionHandler()); - ClosingBtn.addActionListener(new ActionHandler()); - } + } diff --git a/src/main/java/Gui/GameGuiInterface.java b/src/main/java/Gui/GameGuiInterface.java index f0378b9..78d9657 100644 --- a/src/main/java/Gui/GameGuiInterface.java +++ b/src/main/java/Gui/GameGuiInterface.java @@ -17,7 +17,5 @@ public interface GameGuiInterface { void createLayout(); void createButtons(); - - void createRestartButton(); } \ No newline at end of file diff --git a/src/main/java/game/loadNextQuestion.java b/src/main/java/game/loadNextQuestion.java index 6c69b67..1a2fa7f 100644 --- a/src/main/java/game/loadNextQuestion.java +++ b/src/main/java/game/loadNextQuestion.java @@ -59,7 +59,6 @@ public class loadNextQuestion implements ActionListener { public void wrongAnswer() { gameStatus.createLosingPanel(); - gameStatus.createRestartButton(); } }