Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Have Programming Question? Ask it here!

Java timer
0 Answer(s)      3 years and 9 months ago
Posted in : Java Beginners

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 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
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
Timer in the code - Java Beginners
Timer 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 Beginners
Java + 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 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
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
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
Timer - Swing AWT
Timer  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
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
Countdown timer to show a link
Countdown timer to show a link  Hi to everyone! I have this code, which is basically a countdown widget...what I want is that when the countdown finish, a link appears. The thing is that my musical group will be presenting an EP
JavaScript Clock Timer
JavaScript Clock Timer...; In this section, we are going to show you a clock timer using JavaScript... than 9, then it will add 0 in front of min, sec or hour value like 09 in the timer
ServletContextListener with Timer
In this section, you will learn how to use timer with ServletContextListener to run code snippet after every 1 minute immediate after the application run
Registration timer expired, but client is still registering!
Registration timer expired, but client is still registering!  Registration timer expired, but client is still registering
J2ME Timer MIDlet Example
J2ME Timer MIDlet Example       This Example shows how to use of timer class. In this example we are using the Timer class to create the time of execution  of application
Retrieval data from database against timer
Retrieval data from database against timer  Please send me a sample timer code which retrieve data from the database against timer in JSP
J2ME Timer Animation
J2ME Timer Animation       This application illustrates how to use the Timer class..., which helps you to understand using of timer class for drawing the canvas
Scheduling a Timer Task
Scheduling a Timer Task       In this section, you can learn how to schedule a timer task to run... the timer task at a certain time means the task will work only once while you
Please tell me how can i convert string to timer
Please tell me how can i convert string to timer  Please tell me how can i convert string to timer
Comparison between the types of sorting in java
program in java compare between selection,insertion,bubble,merge,quick sort In terms of timer and put all types in frame and find the timer for example array 0-10000 the program select random value and it found timer for all types
java - Java Server Faces Questions
java  how to write the code for a schedular in java plz help in this i will be thank ful to u   hi friend, import java.util.*; public class SchedularTest { private final Timer timer = new Timer(); int
Java Programming: Solution to Programming Exercise
POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... a Timer. Add a Timer to the original source code,, to display the elapsed time in seconds. Create the timer in the mousePressed() routine when
Java Memory Leak - Java Beginners
Java Memory Leak  I am having a memory leak in my java version... is increased to two possible points. The last step before the my game timer runs, (this.pack()), or the first execution of the game/pregame menu timer's loops run
java-script,jsp - JSP-Servlet
java-script,jsp   how can i shift to other page when my timer shows t<=0 .i.e timeout?   Hi Friend, Try the following code: timer.jsp: var time = null function go() { window.location = 'form.jsp
Jsp count and java bean - JSP-Servlet
Jsp count and java bean  Please am on a project and i want to create a countdown timer that will have this format HH:MM:SS. Am working with jsp and java beans please somebody help.  Hi Friend, Try the following
Java swing - Java Beginners
Java swing  Hi, I want to copy the file from one directory... = 1000; int i; JLabel label; JProgressBar pb; Timer timer; JButton button...(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); timer
Using Progress Bar in java apps
Using Progress Bar in java apps  Please, i am writing a program in java to read a file, perform some operation on each line of the file and them...{ int i=0; Timer timer; public ProgressBarExample() { final JLabel
java script - Development process
java script  Hi guys, can anybody tell me how to create...(){ window.location.reload() } window.onresize = createMenu; var timer = null; var...) { timer=setTimeout( "hideAll()" , timecount
Java Programming: Section 7.6
Section 7.6 Timers, Animation, and Threads JAVA IS A MULTI... be running at the same time. To say that Java is a multi-threaded language means that a Java program can create one or more threads which will then run
Progress Bar in Java Swing
Progress Bar in Java Swing     ... in java swing. This section shows you how the progress bar starts and stops with the timer. Through the given example you can understand how the progress bar
Appending Strings - Java Tutorials
.style1 { text-align: center; } Appending Strings In java, the two... three tasks to compare performance. For this we also crate a separate timer class to measure the time taken. First we will create a timer class to record
java.util - Java Interview Questions
description of java.util PackageThe Java util package contains the collections framework..., internationalization, and miscellaneous utility classesThe util package of java provides... learn all the java utility packages classes and interfaces.The classes
java - Java Beginners
it in console.By using timer concept or thread or some other concepts.  Hi
java - Java Beginners
it in console.I want code using timer concept
Java Script Help
Java Script Help  I have written a countdown timer using javascript as Countdown.html. It works fine in Mozila Firefox. But Not working in IE. Pls....' window.location = 'crdtd.php?q=b
java  diff bt core java and java
Controlling Machines Remotely with Java - Java Tutorials
Controlling Machines Remotely with Java 2004-07-08 The Java Specialists' Newsletter [Issue 091] - Controlling Machines Remotely with Java Author... either via email or RSS. Welcome to the 91st edition of The Java(tm
java  what is java
Java   Whether Java is pure object oriented Language
java  different between java & core java
java  explain technologies are used in java now days and structure java
java   why iterator in java if we for loop
JAVA  how the name came for java language as "JAVA
java  what is java reflection
java  is java open source