Timer class reworked

SavePgn^2
Justin 2025-06-23 20:47:28 +02:00
parent cdc418afb4
commit 12bea41b1e
1 changed files with 1 additions and 21 deletions

View File

@ -7,30 +7,19 @@ public class Timer {
private Runnable onTimeout;
private Consumer<Integer> onTick;
/**
* Erstellt einen neuen Timer mit Startzeit in Minuten und Sekunden.
*/
public Timer(int minutes, int seconds) {
this.secondsLeft = minutes * 60 + seconds;
}
/**
* Setzt den Timeout-Callback.
*/
public void setOnTimeout(Runnable onTimeout) {
this.onTimeout = onTimeout;
}
/**
* Setzt den Tick-Callback (wird jede Sekunde aufgerufen).
*/
public void setOnTick(Consumer<Integer> onTick) {
this.onTick = onTick;
}
/**
* Startet oder setzt den Timer fort.
*/
public void start() {
if (swingTimer != null && swingTimer.isRunning()) {
swingTimer.stop();
@ -50,18 +39,12 @@ public class Timer {
swingTimer.start();
}
/**
* Stoppt den Timer.
*/
public void stop() {
if (swingTimer != null) {
swingTimer.stop();
}
}
/**
* Setzt den Timer auf die gegebene Zeit zurück.
*/
public void reset(int minutes, int seconds) {
stop();
this.secondsLeft = minutes * 60 + seconds;
@ -70,9 +53,6 @@ public class Timer {
}
}
/**
* Gibt die aktuelle Restzeit in Sekunden zurück.
*/
public int getSecondsLeft() {
return secondsLeft;
}