So I'm fairly new to java and im making a text based game project using switch statements in different methods. I'm trying to put a 10 sec timer on the user input. I have the timer code working but i cannot get it to work with the user input. My code is way to long to put in this but i can show what the code looks like for the count down if that helps. the if statement doesn't work just something i was trying.
Timer myTimer = new Timer();
TimerTask task = new TimerTask()
{
public void run()
{
secondsPassed --;
System.out.println("secondes passed: " + secondsPassed);
if(str.equals("") || secondsPassed == 0)
{
System.exit(0);
task.cancel();
}
}
};
public void start(){
myTimer.scheduleAtFixedRate(task,1000,1000);
}