|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.ecl.datepicker.util.Timer
public class Timer
Causes the run() method of runnables to be invoked by the
user-interface thread after the specified delay and period milliseconds have
elapsed.
Setting up a timer involves creating a Timer object,
registering one or more runnables on it, and starting the timer using the
start method. For example, the following code creates and
starts a timer that runs a runnable one per second (as specified by the first
argument to the Timer constructor). The second argument to the
Timer contructor specifies a runnable to run.
int period = 1000; // milliseconds
Runnable runnable = new Runnable() {
public void run() {
// ...Perform what you want...
}
}
(new Timer(period, runnable)).start();
Each Timer has one or more runnables and a period.
When period milliseconds have passed, the Timer run
its runnables. By default, this cycle repeats until the stop
method is called. If you want the timer to run only once, invoke
setRepeats(false) or setPeriod(0) on the timer.
To make the delay before the first run different from the period, use
setDelay method or Timer(delay, period, runnable)
constructor.
| Field Summary | |
|---|---|
static int |
DAY
Number of milliseconds in one day. |
static int |
HOUR
Number of milliseconds in one hour. |
static int |
MINUTE
Number of milliseconds in one minute. |
static int |
SECOND
Number of milliseconds in one second. |
| Constructor Summary | |
|---|---|
Timer(int delay,
int period,
Runnable runnable)
Creates a Timer that will run its runnables after
delay and than every period milliseconds. |
|
Timer(int period,
Runnable runnable)
Creates a Timer that will run its runnables every
period milliseconds. |
|
| Method Summary | |
|---|---|
void |
addRunnable(Runnable runnable)
Adds the given runnable to this timer to run when ringing. |
int |
getDelay()
Returns the Timer's delay. |
int |
getPeriod()
Returns the Timer's period, in milliseconds, between
running its runnables. |
boolean |
isRepeats()
Returns true (the default) if the Timer
will run its runnables multiple times. |
boolean |
isRunning()
Returns true if the Timer is running. |
void |
removeRunnable(Runnable runnable)
Removes the given runnable from this timer. |
void |
restart()
Restarts the Timer |
void |
setDelay(int delay)
Sets the Timer's delay, which by default is the same as
the period. |
void |
setPeriod(int period)
Sets the Timer's period, the number of milliseconds
between successive runnings of its runnables. |
void |
setRepeats(boolean repeats)
if repeats is false, instructs the Timer to
run its runnables only one or to stop if already running. |
void |
start()
Starts the Timer, causing it to start running its
runnables. |
void |
stop()
Stops the Timer, causing it to stop running its
runnables. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int SECOND
public static final int MINUTE
public static final int HOUR
public static final int DAY
| Constructor Detail |
|---|
public Timer(int delay,
int period,
Runnable runnable)
Timer that will run its runnables after
delay and than every period milliseconds.
delay - the delay, in milliseconds, between the start
method and the first runnables running by this timerperiod - the number of milliseconds between runnables runningrunnable - an initial runnable, can be null
public Timer(int period,
Runnable runnable)
Timer that will run its runnables every
period milliseconds.
period - the number of milliseconds between runnables runningrunnable - an initial runnable, can be null| Method Detail |
|---|
public void addRunnable(Runnable runnable)
runnable to this timer to run when ringing.
runnable - the runnable to addpublic int getDelay()
Timer's delay.
Timer's delay.setDelay(int),
getPeriod()public int getPeriod()
Timer's period, in milliseconds, between
running its runnables.
setPeriod(int)public boolean isRepeats()
true (the default) if the Timer
will run its runnables multiple times.
true if is repeats; otherwise, falsesetRepeats(boolean),
setPeriod(int)public boolean isRunning()
true if the Timer is running.
true if is running; otherwise, falsestart(),
stop()public void removeRunnable(Runnable runnable)
runnable from this timer.
runnable - the runnable to removepublic void restart()
Timer, canceling any pending runnings and
causing it to run with its delay.
public void setDelay(int delay)
Timer's delay, which by default is the same as
the period. This is used only for the first running. Subsequent running
are spaced using the period property.
delay - the delay, in milliseconds, between the start
method and the first runnables running by this timergetDelay(),
setPeriod(int)public void setPeriod(int period)
Timer's period, the number of milliseconds
between successive runnings of its runnables. If the given
period is zero and the Timer is repeats,
then setRepeats(false) will be invoked.
period - the period in millisecondsgetPeriod(),
setDelay(int)public void setRepeats(boolean repeats)
repeats is false, instructs the Timer to
run its runnables only one or to stop if already running.
repeats - specify false to make the timer stop after
first running its runnablesisRepeats(),
setPeriod(int)public void start()
Timer, causing it to start running its
runnables.
stop()public void stop()
Timer, causing it to stop running its
runnables.
start()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||