Browse Source

Add TimerLable class with basic logic

feature_Minesweeper_Timer
kfkama 3 years ago
parent
commit
f902c3550b
  1. 2
      src/main/java/Minesweeper/MinesweeperGame.java
  2. 38
      src/main/java/Minesweeper/TimerLable.java

2
src/main/java/Minesweeper/MinesweeperGame.java

@ -12,7 +12,7 @@ public class MinesweeperGame extends JPanel {
public MinesweeperGame(int _playfieldSize, int _bombAmount) { public MinesweeperGame(int _playfieldSize, int _bombAmount) {
this.setSize(WIDTH, HEIGTH); this.setSize(WIDTH, HEIGTH);
setLayout(null); setLayout(null);
playfield = new Playfield(this, _playfieldSize, _bombAmount );
playfield = new Playfield(this, _playfieldSize, _bombAmount);
} }
public static void main(String[] args) { public static void main(String[] args) {

38
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();
}
}
Loading…
Cancel
Save