Class Timer
java.lang.Object
org.openpatch.scratch.extensions.timer.Timer
The Timer class provides methods for timing events in a graphical application. It allows checking
if a specified number of milliseconds has passed since the last time a method was called, or if a
specified interval has passed.
Usage example:
Timer timer = new Timer(); if (timer.everyMillis(1000)) { // Do something every second } if (timer.forMillis(5000)) { // Do something for 5 seconds } if (timer.afterMillis(2000)) { // Do something after 2 seconds } if (timer.intervalMillis(1000)) { // Do something every second }
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
afterMillis
(int millis) Checks if the specified number of milliseconds has passed since the method was first called.boolean
everyMillis
(int millis) Checks if the specified number of milliseconds has passed since the last time this method returned true.boolean
forMillis
(int millis) Checks if the specified amount of milliseconds has passed since the method was first called.boolean
intervalMillis
(int millis) Checks if the specified interval in milliseconds has passed.boolean
intervalMillis
(int millis, boolean skipFirst) Checks if the specified interval in milliseconds has passed.boolean
intervalMillis
(int millis1, int millis2) Checks if the specified interval in milliseconds has passed.boolean
intervalMillis
(int millis1, int millis2, boolean skipFirst) Checks if the specified interval in milliseconds has passed.static int
millis()
Returns the number of milliseconds since the program started.void
reset()
Resets the timer.
-
Constructor Details
-
Timer
public Timer()Constructs a new Timer object.
-
-
Method Details
-
reset
public void reset()Resets the timer. -
millis
public static int millis()Returns the number of milliseconds since the program started.- Returns:
- the number of milliseconds since the program started
-
everyMillis
public boolean everyMillis(int millis) Checks if the specified number of milliseconds has passed since the last time this method returned true.- Parameters:
millis
- The number of milliseconds to wait before returning true.- Returns:
- true if the specified number of milliseconds has passed since the last call that returned true, false otherwise.
-
forMillis
public boolean forMillis(int millis) Checks if the specified amount of milliseconds has passed since the method was first called. If the method is called for the first time, it initializes the start time.- Parameters:
millis
- the number of milliseconds to check against- Returns:
- true if the current time is less than the start time plus the specified milliseconds, false otherwise
-
afterMillis
public boolean afterMillis(int millis) Checks if the specified number of milliseconds has passed since the method was first called.- Parameters:
millis
- the number of milliseconds to check against- Returns:
- true if the specified number of milliseconds has passed since the method was first called, false otherwise
-
intervalMillis
public boolean intervalMillis(int millis) Checks if the specified interval in milliseconds has passed.- Parameters:
millis
- the interval in milliseconds to check- Returns:
- true if the interval has passed, false otherwise
-
intervalMillis
public boolean intervalMillis(int millis, boolean skipFirst) Checks if the specified interval in milliseconds has passed.- Parameters:
millis
- the interval in milliseconds to checkskipFirst
- if true, the first interval will be skipped- Returns:
- true if the interval has passed, false otherwise
-
intervalMillis
public boolean intervalMillis(int millis1, int millis2) Checks if the specified interval in milliseconds has passed.- Parameters:
millis1
- the first interval in milliseconds to checkmillis2
- the second interval in milliseconds to check- Returns:
- true if the interval has passed, false otherwise
-
intervalMillis
public boolean intervalMillis(int millis1, int millis2, boolean skipFirst) Checks if the specified interval in milliseconds has passed.- Parameters:
millis1
- the first interval in milliseconds to checkmillis2
- the second interval in milliseconds to checkskipFirst
- if true, the first interval will be skipped- Returns:
- true if the interval has passed, false otherwise
-