|
@ -8,11 +8,12 @@ import javax.swing.JLabel; |
|
|
public class TimerLable extends JLabel { |
|
|
public class TimerLable extends JLabel { |
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L; |
|
|
private static final long serialVersionUID = 1L; |
|
|
private int counter = 0; |
|
|
|
|
|
|
|
|
protected int counter = 0; |
|
|
|
|
|
private Helper task; |
|
|
|
|
|
|
|
|
public void start() { |
|
|
public void start() { |
|
|
Timer timer = new Timer(); |
|
|
Timer timer = new Timer(); |
|
|
TimerTask task = new Helper(this); |
|
|
|
|
|
|
|
|
task = new Helper(this); |
|
|
|
|
|
|
|
|
timer.schedule(task, 0, 1000); |
|
|
timer.schedule(task, 0, 1000); |
|
|
} |
|
|
} |
|
@ -20,12 +21,18 @@ public class TimerLable extends JLabel { |
|
|
public void update() { |
|
|
public void update() { |
|
|
setText(String.valueOf(++counter)); |
|
|
setText(String.valueOf(++counter)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void reset() { |
|
|
|
|
|
task.reset = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Helper extends TimerTask |
|
|
class Helper extends TimerTask |
|
|
{ |
|
|
{ |
|
|
public static int i = 0; |
|
|
|
|
|
|
|
|
public boolean reset; |
|
|
|
|
|
public static int i = 0; |
|
|
private TimerLable timerLable; |
|
|
private TimerLable timerLable; |
|
|
|
|
|
|
|
|
public Helper(TimerLable _timerLable) { |
|
|
public Helper(TimerLable _timerLable) { |
|
@ -33,6 +40,10 @@ class Helper extends TimerTask |
|
|
} |
|
|
} |
|
|
public void run() |
|
|
public void run() |
|
|
{ |
|
|
{ |
|
|
|
|
|
if(reset) { |
|
|
|
|
|
reset = false; |
|
|
|
|
|
timerLable.counter = 0; |
|
|
|
|
|
} |
|
|
timerLable.update(); |
|
|
timerLable.update(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |