From 8e80ee7ad4ee4006aa56e92107a02e2923a465c1 Mon Sep 17 00:00:00 2001 From: Leon Montag Date: Fri, 30 Dec 2022 21:20:29 +0100 Subject: [PATCH] refactoring: extract Methods for Interface --- src/main/java/Gui/GuiInterface.java | 13 +++++++++++++ src/main/java/Gui/gui.java | 10 +++++++--- src/main/java/game/runGame.java | 1 - src/main/java/main.java | 3 ++- src/test/java/Gui/guiTest.java | 2 +- 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 src/main/java/Gui/GuiInterface.java diff --git a/src/main/java/Gui/GuiInterface.java b/src/main/java/Gui/GuiInterface.java new file mode 100644 index 0000000..95005f4 --- /dev/null +++ b/src/main/java/Gui/GuiInterface.java @@ -0,0 +1,13 @@ +package Gui; + +public interface GuiInterface { + + void StartMainMenu(); + + void createFrame(); + + void createButtons(); + + void createPanel(); + +} \ No newline at end of file diff --git a/src/main/java/Gui/gui.java b/src/main/java/Gui/gui.java index fe860b3..1eebce7 100644 --- a/src/main/java/Gui/gui.java +++ b/src/main/java/Gui/gui.java @@ -10,19 +10,21 @@ import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; -public class gui { +public class gui implements GuiInterface { public static JFrame Frame; public static JButton StartBtn, CloseBtn; public static JPanel Panel; public static JLabel Label; public static int width = 800, height = 600; - public void StartMainMenu() { + @Override + public void StartMainMenu() { createFrame(); createButtons(); createPanel(); } - public void createFrame(){ + @Override + public void createFrame(){ Frame = new JFrame("MiniGames"); Frame.setSize(width,height); Frame.setLocationRelativeTo(null); @@ -30,6 +32,7 @@ public class gui { Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } + @Override public void createButtons() { StartBtn = new JButton("Starte Spiel"); StartBtn.addActionListener(new StartGameGui()); @@ -38,6 +41,7 @@ public class gui { } + @Override public void createPanel() { Panel = new JPanel(); Panel.setSize(width,height); diff --git a/src/main/java/game/runGame.java b/src/main/java/game/runGame.java index 27d7736..7caab72 100644 --- a/src/main/java/game/runGame.java +++ b/src/main/java/game/runGame.java @@ -39,7 +39,6 @@ public class runGame { return Numlines+1; } - public static String[] readFile(String Path) { BufferedReader reader; String[] Arr = new String[lines]; diff --git a/src/main/java/main.java b/src/main/java/main.java index 7c295f9..06ab944 100644 --- a/src/main/java/main.java +++ b/src/main/java/main.java @@ -1,11 +1,12 @@ +import Gui.GuiInterface; import Gui.gui; public class main { public static void main(String[] args) { // TODO Auto-generated method stub - gui Mainmenu = new gui(); + GuiInterface Mainmenu = new gui(); Mainmenu.StartMainMenu(); } diff --git a/src/test/java/Gui/guiTest.java b/src/test/java/Gui/guiTest.java index 5f7ab48..028947d 100644 --- a/src/test/java/Gui/guiTest.java +++ b/src/test/java/Gui/guiTest.java @@ -9,7 +9,7 @@ class guiTest { @BeforeAll static void setUp() { - gui StartGui = new gui(); + GuiInterface StartGui = new gui(); StartGui.StartMainMenu(); }