Browse Source

Add reset to TimerLable

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

15
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,11 +21,17 @@ public class TimerLable extends JLabel {
public void update() {
setText(String.valueOf(++counter));
}
public void reset() {
task.reset = true;
}
}
class Helper extends TimerTask
{
public boolean reset;
public static int i = 0;
private 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