Java timer

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

Ads









Related Tutorials/Questions & Answers:
Java timer
Java 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; public ToDo ( int seconds ) { timer = new Timer
Java Timer
Java 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 Task
Java Timer Task  How to assign a task in java at specified date & time (with seconds) using threads
code for timer in java netbeans for online test series countdown timer
code for timer in java netbeans for online test series countdown timer  code for timer in java netbeans for online test series countdown timer
java hello and timer alert application
java 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 task
j2me 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 TimerTask
Timer and TimerTask  i have problem of java.lang.IllegalStateException: Task already scheduled or cancelled
Maven dependency for com.spikhalskiy - hashed-wheel-timer version 0.3.0-RC1 is released. Learn to use hashed-wheel-timer version 0.3.0-RC1 in Maven based Java projects
-timer version 0.3.0-RC1 ) in their Java project if it is based on Maven...-wheel-timer released The developers of   com.spikhalskiy - hashed-wheel-timer project have released the latest version of this library on 05 Sep
Insertion Sort Timer
Insertion 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 using javascript
timer using javascript  How to display timer on HTML page using JavaScript
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'
Version of com.rhcloud>timemanager-timer dependency
List of Version of com.rhcloud>timemanager-timer dependency
Version of geronimo>geronimo-timer dependency
List of Version of geronimo>geronimo-timer dependency
Version of com.ineunet>knife-timer dependency
List of Version of com.ineunet>knife-timer dependency
javascript timer countdown
javascript 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 'algo-timer'
ModuleNotFoundError: No module named 'algo-timer'  Hi, My Python... 'algo-timer' How to remove the ModuleNotFoundError: No module named 'algo-timer' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'block-timer'
ModuleNotFoundError: No module named 'block-timer'  Hi, My Python... 'block-timer' How to remove the ModuleNotFoundError: No module named 'block-timer' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'cl-timer'
ModuleNotFoundError: No module named 'cl-timer'  Hi, My Python...-timer' How to remove the ModuleNotFoundError: No module named 'cl-timer... to install padas library. You can install cl-timer python with following
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 '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 '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 'djangocms-timer'
ModuleNotFoundError: No module named 'djangocms-timer'  Hi, My... named 'djangocms-timer' How to remove the ModuleNotFoundError: No module named 'djangocms-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'djangocms-timer'
ModuleNotFoundError: No module named 'djangocms-timer'  Hi, My... named 'djangocms-timer' How to remove the ModuleNotFoundError: No module named 'djangocms-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-timer'
ModuleNotFoundError: No module named 'django-timer'  Hi, My Python... 'django-timer' How to remove the ModuleNotFoundError: No module named 'django-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-timer'
ModuleNotFoundError: No module named 'django-timer'  Hi, My Python... 'django-timer' How to remove the ModuleNotFoundError: No module named 'django-timer' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'django-timer'
ModuleNotFoundError: No module named 'django-timer'  Hi, My Python... 'django-timer' How to remove the ModuleNotFoundError: No module named 'django-timer' error? Thanks   Hi, In your python
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 '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 'function_timer'
ModuleNotFoundError: No module named 'function_timer'  Hi, My... named 'function_timer' How to remove the ModuleNotFoundError: No module named 'function_timer' error? Thanks   Hi, In your python

Ads