|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gnu.glib.Timer
public final class Timer
Timer: an object that executes a Fireable
target object's
fire
method at a specified interval.
For example, here's how an application clock might be implemented, where the
application passes in an Label
object as its pane:
private final Label clockPane = (Label) glade.getWidget("clockLabel"); private Timer clock = new Timer(1000, // one second new Fireable() { public boolean fire() { String dateStr = DateFormat.getDateInstance() .format(new Date()); clockPane.setText(dateStr); return true; // continue firing } }); clock.start();
Note: a Timer generates events on the application's GUI event queue. It therefore is not accurate for short time periods. It also should only be used to directly fire short/fast methods. Longer methods need to be executed in a separate thread.
Fireable
Constructor Summary | |
---|---|
Timer(int interval,
Fireable target)
Create a new Timer object. |
Method Summary | |
---|---|
int |
getInterval()
Returns the interval associated with this Timer. |
boolean |
isRunning()
Returns whether this timer is running. |
void |
setInterval(int interval)
Set the interval associated with this Timer. |
void |
start()
Start this timer object; that is, begin executing its fire method at its specified interval. |
void |
stop()
Stop this timer object; that is, stop executing its fire method at its specified interval. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Timer(int interval, Fireable target)
interval
- the time period between fire
method executions,
in thousandths of a second.target
- the object whose fire() method gets called after the specified
time period elapses.
java.lang.IllegalArgumentException
- if less than one.Method Detail |
---|
public final int getInterval()
fire
method executions, in
thousandths of a second.public final void setInterval(int interval)
interval
- the time period between fire
method executions,
in thousandths of a second.
java.lang.IllegalArgumentException
- if less than one.public final void start()
public final boolean isRunning()
public final void stop()
fire
method returned false
.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |