public class MyTimer
extends java.lang.Object
start()
to start the timer
(or set it to start in the constructor MyTimer(boolean)
. Use peekAtTime()
to check
the current elapsed time since it was started. Use stop()
to stop the timer and
getTime()
to get the elapsed time between the last time the timer was started and stopped.
If you start and stop the timer multiple times, you can get the average time for all start-stops
using the getAvgTime()
method and the total time of all start-stops with getTotalTime()
.
If you want to check if the timer is running, use isRunning()
.Constructor and Description |
---|
MyTimer()
Creates a new timer.
|
MyTimer(boolean start)
Creates a new timer and starts it if start=true.
|
Modifier and Type | Method and Description |
---|---|
double |
getAvgTime()
Returns the average time in seconds recorded over all start-stop calls.
|
double |
getTime()
Returns the elapsed time in seconds since the last start-stop calls.
|
double |
getTotalTime()
Returns the total time in seconds recorded over all start-stop calls.
|
boolean |
isRunning()
Indicates whether this timer is currently running.
|
static void |
main(java.lang.String[] args)
Demo of usage
|
double |
peekAtTime()
Returns the current elapsed time since the timer was started.
|
void |
resetAvgs()
Resets to zero the average and total time recorded over all start-stop calls.
|
boolean |
start()
Starts the timer if it is not running.
|
boolean |
stop()
Stops the timer.
|
public MyTimer()
public MyTimer(boolean start)
start
- if true, then start the timer; if false then don't start the timer.public static void main(java.lang.String[] args)
args
- command line argspublic boolean start()
public boolean stop()
public boolean isRunning()
public double getTime()
peekAtTime()
.public double peekAtTime()
public double getAvgTime()
public double getTotalTime()
public void resetAvgs()