I would like to ask to the user if he could press a key before continuing. Then my program will wait for that during 10 seconds. If nothing is done, then, I would like to be able to exit the program.
My problem is that the function scanner block my program (until the user have pressed a key) and doesn't allow the program to execute the end.
Do you have any idea of what I could do/use instead of scanner? I am just a beginner in java so please, be indulgent with me.
import java.util.Scanner;
public class Test{
public Test(){
Scanner scan = new Scanner(System.in);
boolean first = true;
System.out.println("Press any key to start.\n");
for(int fr = 0; fr <11; fr++){
System.out.println(fr);
try{
Thread.sleep(1000);
} catch (Exception e) {
System.err.println("error -> "+e.getMessage()); // in case of exception, error message
}
if(fr == 10){
Default def = new Default();
}else if(scan.hasNext() == true){
//System.out.println("Hello");
User user = new User(); // or exit, it doesn't matter
}
}
}
}