I am currently making a Who Wants To Be A Millionaire game, I am quite new to GUI but I read my questions and options from a text file, I have previously made the same game on a CLI and I used the scanner class to make the system wait for an input before moving on to the next question, but I am not too sure how to do the same with a GUI, it reads all the questions without stopping. Is there a way to make it wait between questions? or any better options? I don't want to hard code the questions.
Here is the main code that does the question reading part
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
String answer = null;
String question = null;
String a = null;
String b = null;
String c = null;
String d = null;
InputOutput getIO = new InputOutput();
getIO.readQuestions();
for(int counter = 0; counter < 15; counter++)
{
// int q = 0;
question = getIO.readQuestion(); // Read the question
a = getIO.readA(); // Read option a
b = getIO.readB(); // Read option b
c = getIO.readC(); // Read option c
d = getIO.readD(); // Read option d
// System.out.println(a);
// Stored the correct answer from the file for later usage
answer = getIO.readAnswer();
jTextField1.setText(question);
jTextField2.setText(a);
jTextField3.setText(b);
jTextField4.setText(c);
jTextField5.setText(d);
}
}
Here is the InputOutput class
@Override
public void readQuestions() // Method to read the text file
{
try
{
in = new FileReader("./resources/Questions.txt");
read = new BufferedReader(in);
}
catch(FileNotFoundException e){
System.out.println("File not found");
}
}
@Override
public String readQuestion() // Read the first line of the question
{
try
{
getQuestion = read.readLine();
// System.out.println(getQuestion);
}
catch(IOException e){
System.out.println("Error reading from file");
}
return getQuestion;
}
@Override
public String readA() // Read option 'a'
{
try
{
getA = read.readLine();
// System.out.println(getA);
}
catch(IOException e){
System.out.println("Error reading from file");
}
return getA;
}
@Override
public String readB() // Read option 'b'
{
try
{
getB = read.readLine();
//System.out.println(getB);
}
catch(IOException e){
System.out.println("Error reading from file");
}
return getB;
}
@Override
public String readC() //Read option 'c'
{
try
{
getC = read.readLine();
//System.out.println(getC);
}
catch(IOException e){
System.out.println("Error reading from file");
}
return getC;
}
@Override
public String readD() // Read option 'd'
{
try
{
getD = read.readLine();
//System.out.println(getD);
}
catch(IOException e){
System.out.println("Error reading from file");
}
return getD;
}
@Override
public String readAnswer() // Read answer
{
try
{
getAnswer = read.readLine();
}
catch(IOException e){
System.out.println("Error reading from file");
}
return getAnswer;
}
This is how the text file is arranged
What does 'NFL' stand for
a) National Food League
b) National Federation League
c) National Football League
d) National Fighting League
c
what is 9+2*5
a) 55
b) 60
c) 19
d) 40
c