Michael
Java timer
0 Answer(s)      2 years and 6 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 Pages:
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
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
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
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 - 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
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://www.roseindia.net/j2me/timer-midlet.shtml http
Timer and TimerTask
Timer and TimerTask  i have problem of java.lang.IllegalStateException: Task already scheduled or cancelled
timer using javascript
timer using javascript  How to display timer on HTML page using JavaScript
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
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
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 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, StopWatch.java, 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 - 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 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
stopwatch
stopwatch  Java code for stopwatch timer which should start from zero
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 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
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 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
Hacking
Hacking  hi friends.. can any one tell how to hack the ip address using java coding and i need to add timer in frame .. then i want to compare timer value ...pls help me asap.. i ll thank full
java - Security
= true; private Timer timer; private Image ball; private Image apple; private...; } locateStar(); timer = new Timer(DELAY, this); timer.start(); } public void
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 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 help --- <html> <head> </head> <script language
genaral snake game in java - Java Beginners
; private Timer timer; private Image ball; private Image apple...; } locateApple(); timer = new Timer(DELAY, this); timer.start
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
Task Scheduling in JAVA
Task Scheduling in JAVA     ... in company's permanent record. Java provide facility to schedule tasks as per... scheduled time. We can define action to be performed by this timer task
Threads - Java Beginners
Threads  hi, how to execute threads prgm in java? is it using... = new Thread(r, "Timer"); timerThread.start(); printThreadName...://www.roseindia.net/java Thanks Amardeep
javax.swing.Timer
Java Notesjavax.swing.Timer A javax.swing.Timer object calls an action..., or check a server every hour. Java 2 added another class by the same name... name. To Use a Timer import java.awt.event.*; // for ActionListener
Self-reloading XML Property Files - Java Tutorials
Self-reloading XML Property Files 2004-10-01 The Java Specialists... mentioned that I like generics. To me, they improve the Java language... listeners = new CopyOnWriteArrayList(); /** Make a daemon timer to check
Timmer
Timmer  Code for timer in java swing   import javax.swing.... counter = 0; Timer timer; public SimpleDateFormat TIME = new SimpleDateFormat("HH... TimerDemo() { super("Progress bar timer Demo"); setSize(250, 100

Ask Questions?

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.