public class DisplayTimer
extends Object
Timer
Modifier and Type | Field and Description |
---|---|
(package private) boolean |
countdown |
(package private) long |
displayedTimeSeconds
The value to display ...
|
(package private) JLabel |
displayLabel |
(package private) long |
durationTimeMilliseconds |
(package private) boolean |
flashRedAfterExpiration |
(package private) Color |
foreground |
(package private) Timer |
myTimer |
(package private) boolean |
showYellowAfterWarning |
(package private) Date |
startTime |
(package private) Toolkit |
toolkit |
(package private) long |
warningSeconds |
(package private) long |
zeroTimeInMilliseconds |
Constructor and Description |
---|
DisplayTimer(JLabel displayField)
Associates this timer with the given label
|
DisplayTimer(JLabel displayLabel,
boolean countdown,
int durationSeconds) |
Modifier and Type | Method and Description |
---|---|
long |
getWarningSeconds() |
static String |
hms(int intervalSeconds)
Converts number of seconds into a nice 00:00:00 string.
|
boolean |
isFlashRedAfterExpiration() |
boolean |
isRunning() |
boolean |
isShowYellowAfterWarning() |
void |
restartTimer(int countdownSeconds)
Reset the timer to the countdown seconds and start over.
|
void |
setCountdownSeconds(int countdownSeconds)
Set the number of seconds to start the countdown.
|
void |
setDisplayLabel(JLabel displayLabel) |
void |
setFlashRedAfterExpiration(boolean flashRedAfterExpiration) |
void |
setShowYellowAfterWarning(boolean showYellowAfterWarning) |
void |
setText(String text) |
void |
setWarningSeconds(long warningSeconds) |
void |
startTimer()
Create a one-second timer for the elapsed time display, and start the
timer.
|
void |
startTimer(int countdownSeconds,
boolean restart)
Begin the countdown for the timer.
|
void |
stopTimer() |
JLabel displayLabel
boolean countdown
long durationTimeMilliseconds
long zeroTimeInMilliseconds
boolean flashRedAfterExpiration
boolean showYellowAfterWarning
long warningSeconds
Toolkit toolkit
long displayedTimeSeconds
Date startTime
Timer myTimer
Color foreground
public DisplayTimer(JLabel displayField)
public DisplayTimer(JLabel displayLabel, boolean countdown, int durationSeconds)
displayLabel
- The field to use for the displaycountdown
- Whether we are counting down from the start value or counting up.startValue
- The starting value in seconds. If zero, then startTimer starts from the current time.
Otherwise startTimer starts with the current time plus the start value.public void setDisplayLabel(JLabel displayLabel)
public void setCountdownSeconds(int countdownSeconds)
countdownSeconds
- Countdown will start here. Note there are no restrictions on the value;
if given a negative number, then it will countdown from that value,
flashing red as it goes.public void setText(String text)
public boolean isFlashRedAfterExpiration()
public void setFlashRedAfterExpiration(boolean flashRedAfterExpiration)
public boolean isShowYellowAfterWarning()
public void setShowYellowAfterWarning(boolean showYellowAfterWarning)
public long getWarningSeconds()
public void setWarningSeconds(long warningSeconds)
public void stopTimer()
public boolean isRunning()
public void restartTimer(int countdownSeconds)
countdownSeconds
- public void startTimer(int countdownSeconds, boolean restart)
countdownSeconds
- the number of seconds to start withrestart
- true if we want to reset a running timer to the countdown seconds; false if we continue
counting down (i.e., ignore this call if the timer is already running)public void startTimer()
public static String hms(int intervalSeconds)