Java timer
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." ) ;
}
}
View Answers
Related Tutorials/Questions & Answers:
Java timerJava timer Hi. I want to use a
timer in one of my
java projects... java.util.Timer;
import java.util.TimerTask;
public class ToDo {
Timer timer;ADS_TO_REPLACE_1
public ToDo ( int seconds ) {
timer = new
Timer Java TimerJava Timer Hai Sir,
I want to know How to schedule a task on first date of every month in
java by using
Java timer.Please help me sir.
thank you,
Shyam
Advertisements
Java Timer TaskJava Timer Task How to assign a task in
java at specified date & time (with seconds) using threads
Timer in the code - Java BeginnersTimer in the code This is the question I posted yesterday:
"I'm trying to write a program that has a text field for input, two buttons and the output text area. A user is asked to type in a number. The first button when pressed
Java + Timer concept - Java BeginnersJava +
Timer concept sir,
I am using swing based model. My form... interval) and retrieve values and print it in console. I want code using
timer... label;
JProgressBar pb;
Timer timer;
JButton button;
public
java hello and timer alert applicationjava hello and
timer alert application Hi,
Please help me create a simple
Java application that can display "Hello world" and current Time alert on mobile device screen using mobile screen emulator.
Regards
j2me timer and timer taskj2me
timer and
timer task have anyone idea to change a direction of bubble, according to changing time.
Please go through the following links:
http://www.roseindia.net/j2me/timer-midlet.shtml
http
Difference between Timer and Thread?Difference between
Timer and Thread? Can anyone tell me about the difference between
Timer and Thread, Why we need to have
Timer in case we have Thread implimentation startegy in
Java Timer and TimerTaskTimer and TimerTask i have problem of java.lang.IllegalStateException: Task already scheduled or cancelled
Insertion Sort TimerInsertion Sort Timer Welcome all
I wanna program in
java find the
timer of insertion sort and find time complexity for random value
thanks all
Timer - Swing AWTTimer How can I make a simple countdown
timer in my GUI? ... {
ProgressMonitor progress;
static int counter = 0;
Timer timer...("Progress bar
timer Demo");
setSize(250, 100);
setDefaultCloseOperation
ModuleNotFoundError: No module named 'timer'ModuleNotFoundError: No module named '
timer' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
timer'
How to remove the ModuleNotFoundError: No module named '
timer'
javascript timer countdownjavascript
timer countdown How to disable/enable the javascript
timer countdown?
<!-- CSS Code -->
#txt {
border:none;
font... = "yourpage.htm" // redirects to specified page once
timer ends and ok button
ModuleNotFoundError: No module named 'code-timer'ModuleNotFoundError: No module named 'code-
timer' Hi,
My Python... 'code-
timer'
How to remove the ModuleNotFoundError: No module named 'code-
timer' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'easy-timer'ModuleNotFoundError: No module named 'easy-
timer' Hi,
My Python... 'easy-
timer'
How to remove the ModuleNotFoundError: No module named 'easy-
timer' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'easy-timer'ModuleNotFoundError: No module named 'easy-
timer' Hi,
My Python... 'easy-
timer'
How to remove the ModuleNotFoundError: No module named 'easy-
timer' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'noop-timer'ModuleNotFoundError: No module named 'noop-
timer' Hi,
My Python... 'noop-
timer'
How to remove the ModuleNotFoundError: No module named 'noop-
timer' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'nose-timer'ModuleNotFoundError: No module named 'nose-
timer' Hi,
My Python... 'nose-
timer'
How to remove the ModuleNotFoundError: No module named 'nose-
timer' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'perf-timer'ModuleNotFoundError: No module named 'perf-
timer' Hi,
My Python... 'perf-
timer'
How to remove the ModuleNotFoundError: No module named 'perf-
timer' error?
Thanks
Hi,
In your python environment you
ModuleNotFoundError: No module named 'pref_timer'ModuleNotFoundError: No module named 'pref_
timer' Hi,
My Python... 'pref_
timer'
How to remove the ModuleNotFoundError: No module named 'pref_
timer' error?
Thanks
Hi,
In your python environment you