Thread: Java Timer
View Single Post
Old 12-28-2007, 10:35 AM   PM User | #8
CodeJibblets
New to the CF scene

 
Join Date: Dec 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
CodeJibblets is an unknown quantity at this point
Adding value to this thread

For Timer you need at least the following:

1) Add your import APIs
import java.util.*; // need this for the timer "java.util.Timer;" works too
import java.awt.event.*; // need this for your actionListener "java.awt.event.ActionListener;" works too)

2) Create your Timer (Milliseconds, action) *this is encapsulated code to reduce wordage; 500 below is wait in Milliseconds- FYI
Timer timer = new Timer(500, new ActionListener() {
public void actionToDo(ActionEvent e) {
//Your action code here
}
}); // closes timer's loaded constructor

3)Start your timer
timer.start(); // start now, wait 500 milliseconds and do my action code!
*timer.stop(); // stops your timer

I used this to change name of button after it was pressed then return to the orginal label. *timer.stop() wasn't required for a one time action event; good to use in a cycling function.
CodeJibblets is offline   Reply With Quote