From 903f92aaa169137444b7123664dffa920b6b75db Mon Sep 17 00:00:00 2001 From: Leon Montag Date: Fri, 30 Dec 2022 16:07:27 +0100 Subject: [PATCH] Display the Question in the Gui --- QandA/Questions.txt | 1 + src/main/java/Gui/GameGui.java | 1 + src/main/java/Gui/StartGameGui.java | 2 +- src/main/java/game/runGame.java | 20 +++++++++++++------- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/QandA/Questions.txt b/QandA/Questions.txt index e69de29..da4edb4 100644 --- a/QandA/Questions.txt +++ b/QandA/Questions.txt @@ -0,0 +1 @@ +Wie hoch ist der Eifelturm? \ No newline at end of file diff --git a/src/main/java/Gui/GameGui.java b/src/main/java/Gui/GameGui.java index d31e2fc..65ccf3a 100644 --- a/src/main/java/Gui/GameGui.java +++ b/src/main/java/Gui/GameGui.java @@ -16,6 +16,7 @@ public class GameGui { public static JPanel MainPanel, ButtonPanel, headingPanel; public static JLabel Headline,QuestionLabel; public static JButton AnswersBtn1,AnswersBtn2,AnswersBtn3,AnswersBtn4; +public static int questionNr = 0; GridLayout grid; GridBagConstraints gbc; diff --git a/src/main/java/Gui/StartGameGui.java b/src/main/java/Gui/StartGameGui.java index b964c53..1c51367 100644 --- a/src/main/java/Gui/StartGameGui.java +++ b/src/main/java/Gui/StartGameGui.java @@ -15,7 +15,7 @@ public class StartGameGui implements ActionListener { Gui.createGui(); runGame rungame = new runGame(); - rungame.run(); + rungame.run(GameGui.questionNr); } } diff --git a/src/main/java/game/runGame.java b/src/main/java/game/runGame.java index 021d5f8..3be5902 100644 --- a/src/main/java/game/runGame.java +++ b/src/main/java/game/runGame.java @@ -4,25 +4,31 @@ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; +import Gui.GameGui; + public class runGame { public static String QuestionsPath = "QandA/Questions.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() { - CountFileLines(QuestionsPath); - readFile(QuestionsPath); + public void run(int i) { + GameGui.QuestionLabel.setText(arrQuestions[i]); + } - public int CountFileLines(String Path) { + public static int CountFileLines(String Path) { + int Numlines = 0; try { BufferedReader reader = new BufferedReader(new FileReader(Path)); while (reader.readLine() != null) { - lines++; + Numlines++; } } catch (IOException e) { e.printStackTrace(); } - return lines; + return Numlines; }