From 2e2d7fb427e7c3dd4d6ba95c7cb6e7ff3c0cbd6d Mon Sep 17 00:00:00 2001 From: Leon Montag Date: Fri, 30 Dec 2022 21:09:30 +0100 Subject: [PATCH] refactoring: extract Methods for Interface --- src/main/java/Gui/GameGui.java | 8 +++++++- src/main/java/Gui/GameGuiInterface.java | 17 +++++++++++++++++ src/main/java/Gui/StartGameGui.java | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/main/java/Gui/GameGuiInterface.java diff --git a/src/main/java/Gui/GameGui.java b/src/main/java/Gui/GameGui.java index 2181b0c..a2d8a0d 100644 --- a/src/main/java/Gui/GameGui.java +++ b/src/main/java/Gui/GameGui.java @@ -11,7 +11,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; -public class GameGui { +public class GameGui implements GameGuiInterface { public static JPanel MainPanel, ButtonPanel, headingPanel; public static JLabel Headline,QuestionLabel; @@ -20,6 +20,7 @@ public static int questionNr = 0; GridLayout grid; GridBagConstraints gbc; + @Override public void createGui() { CreatePanel(); createHeadline(); @@ -28,6 +29,7 @@ GridBagConstraints gbc; createButtons(); } + @Override public void CreatePanel(){ MainPanel = new JPanel(); ButtonPanel = new JPanel(); @@ -37,6 +39,7 @@ GridBagConstraints gbc; headingPanel.setLayout(grid); gui.Frame.add(MainPanel); } + @Override public void createHeadline() { Headline = new JLabel("Wer wird Millionär?"); headingPanel.add(Headline); @@ -44,6 +47,7 @@ GridBagConstraints gbc; Headline.setHorizontalAlignment(JLabel.CENTER); Headline.setFont(new Font("Serif", Font.BOLD, 28)); } + @Override public void createQuestionLabel() { QuestionLabel = new JLabel("Questions"); MainPanel.add(QuestionLabel); @@ -51,6 +55,7 @@ GridBagConstraints gbc; QuestionLabel.setVerticalAlignment(JLabel.NORTH); headingPanel.add(QuestionLabel); } + @Override public void createLayout() { ButtonPanel.setLayout(new GridBagLayout()); gbc = new GridBagConstraints(); @@ -61,6 +66,7 @@ GridBagConstraints gbc; gbc.ipady = 100; } + @Override public void createButtons() { AnswersBtn1 = new JButton(); gbc.gridx = 0; diff --git a/src/main/java/Gui/GameGuiInterface.java b/src/main/java/Gui/GameGuiInterface.java new file mode 100644 index 0000000..c1efd62 --- /dev/null +++ b/src/main/java/Gui/GameGuiInterface.java @@ -0,0 +1,17 @@ +package Gui; + +public interface GameGuiInterface { + + void createGui(); + + void CreatePanel(); + + void createHeadline(); + + void createQuestionLabel(); + + void createLayout(); + + void createButtons(); + +} \ No newline at end of file diff --git a/src/main/java/Gui/StartGameGui.java b/src/main/java/Gui/StartGameGui.java index fc7ab67..d299107 100644 --- a/src/main/java/Gui/StartGameGui.java +++ b/src/main/java/Gui/StartGameGui.java @@ -14,7 +14,7 @@ public class StartGameGui implements ActionListener { startGame(); } public void startGame() { - GameGui Gui = new GameGui(); + GameGuiInterface Gui = new GameGui(); Gui.createGui(); runGame rungame = new runGame();