Class AlarmClock

java.lang.Object
  |
  +--AlarmClock
All Implemented Interfaces:
ActionListener, EventListener

public class AlarmClock
extends Object
implements ActionListener

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

REPEAT_DELAY

public static final int REPEAT_DELAY
Constant representing the number of milliseconds between the alarm going off, again and again, when it is set to repeat.

See Also:
Constant Field Values

SNOOZE_DELAY

public static final int SNOOZE_DELAY
Constant representing the number of milliseconds you get when you hit the snooze before the alarm goes off again.

See Also:
Constant Field Values
Constructor Detail

AlarmClock

public AlarmClock(String message)
Constructs an AlarmClock with the given message.

Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
This method is the callback that is used by the internal Timer object.

Specified by:
actionPerformed in interface ActionListener

setRepeats

public void setRepeats(boolean flag)
Turns repeat mode on or off depending on the value of the given flag.


isSet

public boolean isSet()
Returns true if and only if this AlarmClock is set to go off at some point in the future.


set

public void set()
Sets this AlarmClock so that it will go off in getDelay() milliseconds.


turnOff

public void turnOff()
Turns off this AlarmClock. After this method executes the alarm is no longer set.


setDelay

public 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.


getDelay

public int getDelay()
Returns the current delay, whether or not the alarm is set.


goOff

public void goOff()
Forces the alarm to go off.


getMessage

public String getMessage()
Returns the message that is printed by this AlarmClock when it goes off.


setMessage

public void setMessage(String message)
Changes the message that is printed by this AlarmClock when it goes off to the given message.


snooze

public 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.


toString

public String toString()
Returns a textual representation of this AlarmClock.

Overrides:
toString in class Object