
Hi. I want to use a timer in one of my java projects and I found one online, it allows the user to type an input from the keyboard for predetermined number of seconds and it's exactly what I want but I can't find out how to store the input in a string. Please show me how. Here's the code:
import java.util.Timer; import java.util.TimerTask;
public class ToDo { Timer timer;
public ToDo ( int seconds ) { timer = new Timer ( ) ; timer.schedule ( new ToDoTask ( ) , seconds*1000 ) ; }
class ToDoTask extends TimerTask { public void run ( ) { System.out.println ( "\nOK, It's time to do something!" ) ; timer.cancel ( ) ; //Terminate the thread } }
public static void main ( String args [ ] ) { System.out.println ( "Schedule something to do in 5 seconds." ) ; new ToDo ( 5 ) ; System.out.println ( "Waiting." ) ; } }
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.