Browse Source

Add reset to TimerLable

feature_Minesweeper_Timer
kfkama 3 years ago
parent
commit
8128061c09
  1. 17
      src/main/java/Minesweeper/TimerLable.java

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