From 8128061c09986773d9a3c684ef4e9c77dca2f236 Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 20:07:22 +0100 Subject: [PATCH] Add reset to TimerLable --- src/main/java/Minesweeper/TimerLable.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/Minesweeper/TimerLable.java b/src/main/java/Minesweeper/TimerLable.java index a194bbf..ae08055 100644 --- a/src/main/java/Minesweeper/TimerLable.java +++ b/src/main/java/Minesweeper/TimerLable.java @@ -8,11 +8,12 @@ import javax.swing.JLabel; public class TimerLable extends JLabel { private static final long serialVersionUID = 1L; - private int counter = 0; + protected int counter = 0; + private Helper task; public void start() { Timer timer = new Timer(); - TimerTask task = new Helper(this); + task = new Helper(this); timer.schedule(task, 0, 1000); } @@ -20,12 +21,18 @@ public class TimerLable extends JLabel { public void update() { setText(String.valueOf(++counter)); } + + public void reset() { + task.reset = true; + } + } class Helper extends TimerTask { - public static int i = 0; + public boolean reset; + public static int i = 0; private TimerLable timerLable; public Helper(TimerLable _timerLable) { @@ -33,6 +40,10 @@ class Helper extends TimerTask } public void run() { + if(reset) { + reset = false; + timerLable.counter = 0; + } timerLable.update(); } } \ No newline at end of file