Monday, March 22, 2010
Alarm Timer
// If the user selected date and/or time that is earlier
// than today, set a flag. We are using getTime()
// method of the Date class, which returns the # of
// milliseconds since January 1, 1970
// Create a new timer
tm = new Timer();
tt = new AlarmTimer();
// Amount of time to delay
long amount = dfAlarmTime.getDate().getTime() -
currentTime.getTime();
tm.schedule(tt,amount);
// Remove the commands
fmMain.removeCommand(cmAlarm);
fmMain.removeCommand(cmReset);
// Remove the DateField
fmMain.delete(dateIndex);
// Change the Form message
fmMain.setTitle("Sleeping...");
}
} else if (c == cmReset) {
// Reset to the current date/time
dfAlarmTime.setDate(currentTime = new Date());
} else if (c == cmExit) {
destroyApp(false);
notifyDestroyed();
}
}
// Handle the timer task
private class AlarmTimer extends TimerTask {
public final void run() {
Alert al = new Alert("Time to wake up!");
al.setTimeout(Alert.FOREVER);
al.setType(AlertType.ALARM);
AlertType.ERROR.playSound(display);
display.setCurrent(al);
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment