Results 1 to 5 of 5
Thread: Using a Timer
- 07-10-2011, 09:34 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
Using a Timer
I am fairly new to Java and I'm just trying to figure out how to use a timer to do something in a certain amount of time. What I'm trying to do, specifically, is make it so that each letter of a string appears after a certain amount of time. Here's my code:
As you can see I have a Timer object created(I'm not even sure if I even used the correct parameters) but it's not implemented because I don't know how to use it. Any help would be appreciated.Java Code:import java.util.Timer; import java.util.TimerTask; public class Main { public static void main(String[] args) { String helloString = "Hello Everybody!"; Timer time = new Timer(1000, this); int counter; for(counter = 0; counter == helloString.length(); counter++ ) { System.out.println(helloString.charAt(counter)); } } }
- 07-10-2011, 09:37 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,601
- Blog Entries
- 7
- Rep Power
- 17
What does your compiler say about your code?
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 07-10-2011, 10:49 PM #3
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
- 07-10-2011, 11:06 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 11
- Rep Power
- 0
Please somebody help.
-
We are conditioned towards seeing and trying to fix errors if and when we find them, and it was probably obvious to Jos that your code posted does not compile which is likely why he made his recommendation.
Anyway, to answer your possible question, there are at least three Timer classes in the core Java library, two of which you'll commonly use, the javax.swing.Timer for Swing gui applications that need a Timer functionality and the java.util.Timer for non-Swing timer needs. So, you'll first need to ask yourself for what purpose you'll be using the timer eventually, and then next check out the Java API for the Timer class.
Also, we're all volunteers here helping when we have a chance. Please don't bump your post < 12 hours after posting, lest you want to appear impatient.
Similar Threads
-
Timer And Timer Task
By Ashish_jain in forum New To JavaReplies: 3Last Post: 06-22-2011, 09:41 AM -
Stopping a Timer from Inside the timer
By krishnan in forum Java AppletsReplies: 2Last Post: 10-04-2010, 11:15 PM -
Timer
By Learning Java in forum New To JavaReplies: 3Last Post: 08-11-2010, 12:18 PM -
Timer
By barts2108 in forum New To JavaReplies: 4Last Post: 06-08-2010, 06:17 PM -
How to cancel an individual timer in spite of canceling whole timer
By Java Tip in forum java.utilReplies: 0Last Post: 04-04-2008, 02:46 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks