You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1010 B
60 lines
1010 B
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;
|
|
protected int counter = 0;
|
|
private Helper task;
|
|
|
|
public void start() {
|
|
Timer timer = new Timer();
|
|
task = new Helper(this);
|
|
|
|
timer.schedule(task, 0, 1000);
|
|
}
|
|
|
|
public void update() {
|
|
setText(String.valueOf(++counter));
|
|
}
|
|
|
|
public void reset() {
|
|
task.reset = true;
|
|
counter = 0;
|
|
setText(String.valueOf(counter));
|
|
repaint();
|
|
task.stop = false;
|
|
}
|
|
|
|
public void stop() {
|
|
task.stop = true;
|
|
}
|
|
}
|
|
|
|
|
|
class Helper extends TimerTask
|
|
{
|
|
public boolean reset;
|
|
public boolean stop;
|
|
public static int i = 0;
|
|
private TimerLable timerLable;
|
|
|
|
public Helper(TimerLable _timerLable) {
|
|
timerLable = _timerLable;
|
|
}
|
|
public void run()
|
|
{
|
|
if(stop) {
|
|
return;
|
|
}
|
|
if(reset) {
|
|
reset = false;
|
|
timerLable.counter = 0;
|
|
}
|
|
timerLable.update();
|
|
}
|
|
}
|