|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--AlarmClock
An AlarmClock is constructed from a
message string and a delay. The delay is measured
in milliseconds (1 sec = 1000 ms). For example,
> AlarmClock a = new AlarmClock("time for the meeting");
> a.setDelay(10000);
> a.getMessage()
"time for the meeting"
> a.getDelay()
10000
> a
AlarmClock[message=time for the meeting,delay=10000,set=false]
> a.isSet()
false
> a.set();
> g.isSet()
true
>
An AlarmClock uses a built-in
javax.swing.Timer
object to control its behavior.
A Timer has one or more action listeners and a
delay (the time between action events). The delay is
measured in milliseconds. When delay
milliseconds have passes, the timer fires an action
event to all its listeners. By default, this cycle
continues until the timer is stopped.
If you want the timer to fire only once, invoke
setRepeats(false) on the timer.
To make the delay before the first action event
different from the delay between events,
use the setInitialDelay method.
| Field Summary | |
static int |
REPEAT_DELAY
Constant representing the number of milliseconds between the alarm going off, again and again, when it is set to repeat. |
static int |
SNOOZE_DELAY
Constant representing the number of milliseconds you get when you hit the snooze before the alarm goes off again. |
| Constructor Summary | |
AlarmClock(String message)
Constructs an AlarmClock with the given
message. |
|
| Method Summary | |
void |
actionPerformed(ActionEvent e)
This method is the callback that is used by the internal Timer object. |
int |
getDelay()
Returns the current delay, whether or not the alarm is set. |
String |
getMessage()
Returns the message that is printed by this AlarmClock
when it goes off. |
void |
goOff()
Forces the alarm to go off. |
boolean |
isSet()
Returns true if and only if this AlarmClock
is set to go off at some point in the future. |
void |
set()
Sets this AlarmClock so that it will go off in
getDelay() milliseconds. |
void |
setDelay(int delay)
Changes the current delay, i.e., the number of milliseconds it will take for the alarm to go off once it's set, to the given delay. |
void |
setMessage(String message)
Changes the message that is printed by this AlarmClock
when it goes off to the given message. |
void |
setRepeats(boolean flag)
Turns repeat mode on or off depending on the value of the given flag. |
void |
snooze()
Turns off the alarm and puts this AlarmClock in
snooze mode, meaning it will wait for
SNOOZE_DELAY milliseconds and then go off again. |
String |
toString()
Returns a textual representation of this AlarmClock. |
void |
turnOff()
Turns off this AlarmClock. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int REPEAT_DELAY
public static final int SNOOZE_DELAY
| Constructor Detail |
public AlarmClock(String message)
AlarmClock with the given
message.
| Method Detail |
public void actionPerformed(ActionEvent e)
Timer object.
actionPerformed in interface ActionListenerpublic void setRepeats(boolean flag)
flag.
public boolean isSet()
true if and only if this AlarmClock
is set to go off at some point in the future.
public void set()
AlarmClock so that it will go off in
getDelay() milliseconds.
public void turnOff()
AlarmClock. After this method executes
the alarm is no longer set.
public void setDelay(int delay)
delay.
public int getDelay()
public void goOff()
public String getMessage()
AlarmClock
when it goes off.
public void setMessage(String message)
AlarmClock
when it goes off to the given message.
public void snooze()
AlarmClock in
snooze mode, meaning it will wait for
SNOOZE_DELAY milliseconds and then go off again.
public String toString()
AlarmClock.
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||