Browse Source

refactoring: Formating Code

master
Leon Montag 2 years ago
parent
commit
3e6c043e22
  1. 1
      src/main/java/Gui/ActionHandler.java
  2. 2
      src/main/java/Gui/StartGameGui.java
  3. 16
      src/main/java/Gui/gui.java
  4. 6
      src/main/java/game/runGame.java
  5. 25
      src/test/java/Gui/guiTest.java
  6. 13
      src/test/java/game/runGameTest.java
  7. 2
      target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

1
src/main/java/Gui/ActionHandler.java

@ -3,7 +3,6 @@ package Gui;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
public class ActionHandler implements ActionListener { public class ActionHandler implements ActionListener {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {

2
src/main/java/Gui/StartGameGui.java

@ -5,7 +5,6 @@ import java.awt.event.ActionListener;
import game.runGame; import game.runGame;
public class StartGameGui implements ActionListener { public class StartGameGui implements ActionListener {
@Override @Override
@ -13,6 +12,7 @@ public class StartGameGui implements ActionListener {
gui.Panel.setVisible(false); gui.Panel.setVisible(false);
startGame(); startGame();
} }
public void startGame() { public void startGame() {
GameGuiInterface Gui = new GameGui(); GameGuiInterface Gui = new GameGui();
Gui.createGui(); Gui.createGui();

16
src/main/java/Gui/gui.java

@ -23,10 +23,11 @@ public class gui implements GuiInterface {
createButtons(); createButtons();
createPanel(); createPanel();
} }
@Override @Override
public void createFrame(){
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);
Frame.setResizable(false); Frame.setResizable(false);
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -39,12 +40,12 @@ public class gui implements GuiInterface {
CloseBtn = new JButton("Schließen"); CloseBtn = new JButton("Schließen");
CloseBtn.addActionListener(new ActionHandler()); CloseBtn.addActionListener(new ActionHandler());
} }
@Override @Override
public void createPanel() { public void createPanel() {
Panel = new JPanel(); Panel = new JPanel();
Panel.setSize(width,height);
Panel.setSize(width, height);
Panel.setLayout(new GridBagLayout()); Panel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints(); GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridwidth = GridBagConstraints.REMAINDER;
@ -55,13 +56,12 @@ public class gui implements GuiInterface {
Label = new JLabel("MiniGames"); Label = new JLabel("MiniGames");
Label.setHorizontalAlignment(JLabel.CENTER); Label.setHorizontalAlignment(JLabel.CENTER);
Label.setFont(new Font("Serif", Font.BOLD, 28)); Label.setFont(new Font("Serif", Font.BOLD, 28));
Panel.add(Label,gbc);
Panel.add(StartBtn,gbc);
Panel.add(CloseBtn,gbc);
Panel.add(Label, gbc);
Panel.add(StartBtn, gbc);
Panel.add(CloseBtn, gbc);
Frame.add(Panel); Frame.add(Panel);
Frame.setVisible(true); Frame.setVisible(true);
Panel.setVisible(true); Panel.setVisible(true);
} }
} }

6
src/main/java/game/runGame.java

@ -14,7 +14,6 @@ public class runGame {
public static String[] arrAnswers = readFile(AnswersPath); public static String[] arrAnswers = readFile(AnswersPath);
public static String[] splitAns; public static String[] splitAns;
public void run(int i) { public void run(int i) {
splitAns = SplitAnswers(arrAnswers, i); splitAns = SplitAnswers(arrAnswers, i);
GameGui.QuestionLabel.setText(arrQuestions[i]); GameGui.QuestionLabel.setText(arrQuestions[i]);
@ -24,6 +23,7 @@ public class runGame {
GameGui.AnswersBtn4.setText(splitAns[3]); GameGui.AnswersBtn4.setText(splitAns[3]);
GameGui.questionNr++; GameGui.questionNr++;
} }
public static int CountFileLines(String Path) { public static int CountFileLines(String Path) {
int Numlines = 0; int Numlines = 0;
try { try {
@ -36,9 +36,10 @@ public class runGame {
e.printStackTrace(); e.printStackTrace();
} }
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];
@ -57,6 +58,7 @@ public class runGame {
} }
return Arr; return Arr;
} }
public static String[] SplitAnswers(String[] data2, int i) { public static String[] SplitAnswers(String[] data2, int i) {
String[] parts = data2[i].split(","); String[] parts = data2[i].split(",");
return parts; return parts;

25
src/test/java/Gui/guiTest.java

@ -15,40 +15,39 @@ class guiTest {
@Test @Test
void testCreateFrame() { void testCreateFrame() {
//arrange
// arrange
int FrameWitdh = 800; int FrameWitdh = 800;
int FrameHeight = 600; int FrameHeight = 600;
//act
// act
assertEquals(FrameWitdh, gui.Frame.getWidth()); assertEquals(FrameWitdh, gui.Frame.getWidth());
assertEquals(FrameHeight, gui.Frame.getHeight()); assertEquals(FrameHeight, gui.Frame.getHeight());
} }
@Test @Test
public void testCreateButtons() { public void testCreateButtons() {
//arrange
// arrange
String Start = "Starte Spiel"; String Start = "Starte Spiel";
String Close = "Schließen"; String Close = "Schließen";
//act
// act
String StartTarget = gui.StartBtn.getText(); String StartTarget = gui.StartBtn.getText();
String CloseTarget = gui.CloseBtn.getText(); String CloseTarget = gui.CloseBtn.getText();
//assert
assertEquals(Start,StartTarget);
assertEquals(Close,CloseTarget);
// assert
assertEquals(Start, StartTarget);
assertEquals(Close, CloseTarget);
} }
@Test @Test
public void testCreatePanel() { public void testCreatePanel() {
//arrange
// arrange
int NumPanels = 3; int NumPanels = 3;
//act
// act
int TargetNumPanels = gui.Panel.getComponents().length; int TargetNumPanels = gui.Panel.getComponents().length;
//assert
assertEquals(NumPanels,TargetNumPanels);
// assert
assertEquals(NumPanels, TargetNumPanels);
} }
} }

13
src/test/java/game/runGameTest.java

@ -17,7 +17,7 @@ class runGameTest {
@Test @Test
public void testCountFileLinesWithThreeLines() { public void testCountFileLinesWithThreeLines() {
//arrange
// arrange
int numLines = 0; int numLines = 0;
File file; File file;
try { try {
@ -27,18 +27,18 @@ class runGameTest {
writer.write("Zeile 2\n"); writer.write("Zeile 2\n");
writer.write("Zeile 3\n"); writer.write("Zeile 3\n");
writer.close(); writer.close();
//act
// act
numLines = runGame.CountFileLines(file.getAbsolutePath()); numLines = runGame.CountFileLines(file.getAbsolutePath());
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
//assert
// assert
assertEquals(4, numLines); assertEquals(4, numLines);
} }
@Test @Test
public void testReadFile(){
public void testReadFile() {
File file; File file;
try { try {
file = File.createTempFile("temp", ".txt"); file = File.createTempFile("temp", ".txt");
@ -56,11 +56,11 @@ class runGameTest {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Test @Test
public void testSplitAnswers() { public void testSplitAnswers() {
String[] StringToSplit = {"Das,ist,ein,Test", "1,2,3,4"};
String[] StringToSplit = { "Das,ist,ein,Test", "1,2,3,4" };
String[] parts = runGame.SplitAnswers(StringToSplit, 1); String[] parts = runGame.SplitAnswers(StringToSplit, 1);
assertEquals(4, parts.length); assertEquals(4, parts.length);
assertEquals("1", parts[0]); assertEquals("1", parts[0]);
@ -69,5 +69,4 @@ class runGameTest {
assertEquals("4", parts[3]); assertEquals("4", parts[3]);
} }
} }

2
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst

@ -1,6 +1,8 @@
C:\Users\Leon\MiniGameProject\src\main\java\Gui\ActionHandler.java C:\Users\Leon\MiniGameProject\src\main\java\Gui\ActionHandler.java
C:\Users\Leon\MiniGameProject\src\main\java\Gui\GameGuiInterface.java
C:\Users\Leon\MiniGameProject\src\main\java\Gui\gui.java C:\Users\Leon\MiniGameProject\src\main\java\Gui\gui.java
C:\Users\Leon\MiniGameProject\src\main\java\game\runGame.java C:\Users\Leon\MiniGameProject\src\main\java\game\runGame.java
C:\Users\Leon\MiniGameProject\src\main\java\main.java C:\Users\Leon\MiniGameProject\src\main\java\main.java
C:\Users\Leon\MiniGameProject\src\main\java\Gui\StartGameGui.java C:\Users\Leon\MiniGameProject\src\main\java\Gui\StartGameGui.java
C:\Users\Leon\MiniGameProject\src\main\java\Gui\GameGui.java C:\Users\Leon\MiniGameProject\src\main\java\Gui\GameGui.java
C:\Users\Leon\MiniGameProject\src\main\java\Gui\GuiInterface.java
Loading…
Cancel
Save