Browse Source

refactoring: extract Methods for Interface

master
Leon Montag 2 years ago
parent
commit
8e80ee7ad4
  1. 13
      src/main/java/Gui/GuiInterface.java
  2. 10
      src/main/java/Gui/gui.java
  3. 1
      src/main/java/game/runGame.java
  4. 3
      src/main/java/main.java
  5. 2
      src/test/java/Gui/guiTest.java

13
src/main/java/Gui/GuiInterface.java

@ -0,0 +1,13 @@
package Gui;
public interface GuiInterface {
void StartMainMenu();
void createFrame();
void createButtons();
void createPanel();
}

10
src/main/java/Gui/gui.java

@ -10,19 +10,21 @@ import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
public class gui {
public class gui implements GuiInterface {
public static JFrame Frame; public static JFrame Frame;
public static JButton StartBtn, CloseBtn; public static JButton StartBtn, CloseBtn;
public static JPanel Panel; public static JPanel Panel;
public static JLabel Label; public static JLabel Label;
public static int width = 800, height = 600; public static int width = 800, height = 600;
public void StartMainMenu() {
@Override
public void StartMainMenu() {
createFrame(); createFrame();
createButtons(); createButtons();
createPanel(); createPanel();
} }
public void createFrame(){
@Override
public void createFrame(){
Frame = new JFrame("MiniGames"); Frame = new JFrame("MiniGames");
Frame.setSize(width,height); Frame.setSize(width,height);
Frame.setLocationRelativeTo(null); Frame.setLocationRelativeTo(null);
@ -30,6 +32,7 @@ public class gui {
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} }
@Override
public void createButtons() { public void createButtons() {
StartBtn = new JButton("Starte Spiel"); StartBtn = new JButton("Starte Spiel");
StartBtn.addActionListener(new StartGameGui()); StartBtn.addActionListener(new StartGameGui());
@ -38,6 +41,7 @@ public class gui {
} }
@Override
public void createPanel() { public void createPanel() {
Panel = new JPanel(); Panel = new JPanel();
Panel.setSize(width,height); Panel.setSize(width,height);

1
src/main/java/game/runGame.java

@ -39,7 +39,6 @@ public class runGame {
return Numlines+1; return Numlines+1;
} }
public static String[] readFile(String Path) { public static String[] readFile(String Path) {
BufferedReader reader; BufferedReader reader;
String[] Arr = new String[lines]; String[] Arr = new String[lines];

3
src/main/java/main.java

@ -1,11 +1,12 @@
import Gui.GuiInterface;
import Gui.gui; import Gui.gui;
public class main { public class main {
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
gui Mainmenu = new gui();
GuiInterface Mainmenu = new gui();
Mainmenu.StartMainMenu(); Mainmenu.StartMainMenu();
} }

2
src/test/java/Gui/guiTest.java

@ -9,7 +9,7 @@ class guiTest {
@BeforeAll @BeforeAll
static void setUp() { static void setUp() {
gui StartGui = new gui();
GuiInterface StartGui = new gui();
StartGui.StartMainMenu(); StartGui.StartMainMenu();
} }

Loading…
Cancel
Save