Browse Source

Display the Question in the Gui

master
Leon Montag 2 years ago
parent
commit
903f92aaa1
  1. 1
      QandA/Questions.txt
  2. 1
      src/main/java/Gui/GameGui.java
  3. 2
      src/main/java/Gui/StartGameGui.java
  4. 20
      src/main/java/game/runGame.java

1
QandA/Questions.txt

@ -0,0 +1 @@
Wie hoch ist der Eifelturm?

1
src/main/java/Gui/GameGui.java

@ -16,6 +16,7 @@ public class GameGui {
public static JPanel MainPanel, ButtonPanel, headingPanel; public static JPanel MainPanel, ButtonPanel, headingPanel;
public static JLabel Headline,QuestionLabel; public static JLabel Headline,QuestionLabel;
public static JButton AnswersBtn1,AnswersBtn2,AnswersBtn3,AnswersBtn4; public static JButton AnswersBtn1,AnswersBtn2,AnswersBtn3,AnswersBtn4;
public static int questionNr = 0;
GridLayout grid; GridLayout grid;
GridBagConstraints gbc; GridBagConstraints gbc;

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

@ -15,7 +15,7 @@ public class StartGameGui implements ActionListener {
Gui.createGui(); Gui.createGui();
runGame rungame = new runGame(); runGame rungame = new runGame();
rungame.run();
rungame.run(GameGui.questionNr);
} }
} }

20
src/main/java/game/runGame.java

@ -4,25 +4,31 @@ import java.io.BufferedReader;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import Gui.GameGui;
public class runGame { public class runGame {
public static String QuestionsPath = "QandA/Questions.txt"; public static String QuestionsPath = "QandA/Questions.txt";
public static String AnswersPath = "QandA/Answers.txt"; public static String AnswersPath = "QandA/Answers.txt";
public static int lines;
public static int lines = CountFileLines(QuestionsPath);
public static String[] arrQuestions = readFile(QuestionsPath);
public static String[] arrAnswers = readFile(AnswersPath);
public void run(int i) {
GameGui.QuestionLabel.setText(arrQuestions[i]);
public void run() {
CountFileLines(QuestionsPath);
readFile(QuestionsPath);
} }
public int CountFileLines(String Path) {
public static int CountFileLines(String Path) {
int Numlines = 0;
try { try {
BufferedReader reader = new BufferedReader(new FileReader(Path)); BufferedReader reader = new BufferedReader(new FileReader(Path));
while (reader.readLine() != null) { while (reader.readLine() != null) {
lines++;
Numlines++;
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return lines;
return Numlines;
} }

Loading…
Cancel
Save