From f902c3550b2ab4c37492b10a89dc97a195d98b7a Mon Sep 17 00:00:00 2001 From: kfkama Date: Thu, 17 Feb 2022 20:02:43 +0100 Subject: [PATCH] Add TimerLable class with basic logic --- .../java/Minesweeper/MinesweeperGame.java | 2 +- src/main/java/Minesweeper/TimerLable.java | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/java/Minesweeper/TimerLable.java diff --git a/src/main/java/Minesweeper/MinesweeperGame.java b/src/main/java/Minesweeper/MinesweeperGame.java index 8293a18..f31d319 100644 --- a/src/main/java/Minesweeper/MinesweeperGame.java +++ b/src/main/java/Minesweeper/MinesweeperGame.java @@ -12,7 +12,7 @@ public class MinesweeperGame extends JPanel { public MinesweeperGame(int _playfieldSize, int _bombAmount) { this.setSize(WIDTH, HEIGTH); setLayout(null); - playfield = new Playfield(this, _playfieldSize, _bombAmount ); + playfield = new Playfield(this, _playfieldSize, _bombAmount); } public static void main(String[] args) { diff --git a/src/main/java/Minesweeper/TimerLable.java b/src/main/java/Minesweeper/TimerLable.java new file mode 100644 index 0000000..a194bbf --- /dev/null +++ b/src/main/java/Minesweeper/TimerLable.java @@ -0,0 +1,38 @@ +package Minesweeper; + +import java.util.Timer; +import java.util.TimerTask; + +import javax.swing.JLabel; + +public class TimerLable extends JLabel { + + private static final long serialVersionUID = 1L; + private int counter = 0; + + public void start() { + Timer timer = new Timer(); + TimerTask task = new Helper(this); + + timer.schedule(task, 0, 1000); + } + + public void update() { + setText(String.valueOf(++counter)); + } +} + + +class Helper extends TimerTask +{ + public static int i = 0; + private TimerLable timerLable; + + public Helper(TimerLable _timerLable) { + timerLable = _timerLable; + } + public void run() + { + timerLable.update(); + } +} \ No newline at end of file