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.ActionListener;
public class ActionHandler implements ActionListener {
public void actionPerformed(ActionEvent e) {

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

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

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

@ -23,10 +23,11 @@ public class gui implements GuiInterface {
createButtons();
createPanel();
}
@Override
public void createFrame(){
public void createFrame() {
Frame = new JFrame("MiniGames");
Frame.setSize(width,height);
Frame.setSize(width, height);
Frame.setLocationRelativeTo(null);
Frame.setResizable(false);
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -39,12 +40,12 @@ public class gui implements GuiInterface {
CloseBtn = new JButton("Schließen");
CloseBtn.addActionListener(new ActionHandler());
}
@Override
public void createPanel() {
Panel = new JPanel();
Panel.setSize(width,height);
Panel.setSize(width, height);
Panel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridwidth = GridBagConstraints.REMAINDER;
@ -55,13 +56,12 @@ public class gui implements GuiInterface {
Label = new JLabel("MiniGames");
Label.setHorizontalAlignment(JLabel.CENTER);
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.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[] splitAns;
public void run(int i) {
splitAns = SplitAnswers(arrAnswers, i);
GameGui.QuestionLabel.setText(arrQuestions[i]);
@ -24,6 +23,7 @@ public class runGame {
GameGui.AnswersBtn4.setText(splitAns[3]);
GameGui.questionNr++;
}
public static int CountFileLines(String Path) {
int Numlines = 0;
try {
@ -36,9 +36,10 @@ public class runGame {
e.printStackTrace();
}
return Numlines+1;
return Numlines + 1;
}
public static String[] readFile(String Path) {
BufferedReader reader;
String[] Arr = new String[lines];
@ -57,6 +58,7 @@ public class runGame {
}
return Arr;
}
public static String[] SplitAnswers(String[] data2, int i) {
String[] parts = data2[i].split(",");
return parts;

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

@ -15,40 +15,39 @@ class guiTest {
@Test
void testCreateFrame() {
//arrange
// arrange
int FrameWitdh = 800;
int FrameHeight = 600;
//act
// act
assertEquals(FrameWitdh, gui.Frame.getWidth());
assertEquals(FrameHeight, gui.Frame.getHeight());
}
@Test
public void testCreateButtons() {
//arrange
// arrange
String Start = "Starte Spiel";
String Close = "Schließen";
//act
// act
String StartTarget = gui.StartBtn.getText();
String CloseTarget = gui.CloseBtn.getText();
//assert
assertEquals(Start,StartTarget);
assertEquals(Close,CloseTarget);
// assert
assertEquals(Start, StartTarget);
assertEquals(Close, CloseTarget);
}
@Test
public void testCreatePanel() {
//arrange
// arrange
int NumPanels = 3;
//act
// act
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
public void testCountFileLinesWithThreeLines() {
//arrange
// arrange
int numLines = 0;
File file;
try {
@ -27,18 +27,18 @@ class runGameTest {
writer.write("Zeile 2\n");
writer.write("Zeile 3\n");
writer.close();
//act
// act
numLines = runGame.CountFileLines(file.getAbsolutePath());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//assert
// assert
assertEquals(4, numLines);
}
@Test
public void testReadFile(){
public void testReadFile() {
File file;
try {
file = File.createTempFile("temp", ".txt");
@ -56,11 +56,11 @@ class runGameTest {
e.printStackTrace();
}
}
@Test
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);
assertEquals(4, parts.length);
assertEquals("1", parts[0]);
@ -69,5 +69,4 @@ class runGameTest {
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\GameGuiInterface.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\main.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\GuiInterface.java
Loading…
Cancel
Save