Closed mrafsyam closed 8 years ago
Code for a second, left here for reference
package scoreBoard;
import java.util.Timer;
import java.util.TimerTask;
public class TimerDemo {
public static void main(String[] args) {
// instantiate our TimerTask "extended" class
RunEverySecond tasknew = new RunEverySecond();
// instantiate a Timer object
Timer timer = new Timer();
// scheduling the task at fixed rate delay. See http://docs.oracle.com/javase/7/docs/api/java/util/Timer.html#scheduleAtFixedRate(java.util.TimerTask,%20long,%20long)
timer.scheduleAtFixedRate(tasknew,0,1000);
}
}
/*
* TimerTask is an "Abstract" class - cannot be instantiated but can only be extended
* see https://docs.oracle.com/javase/7/docs/api/java/util/TimerTask.html#TimerTask()
*/
class RunEverySecond extends TimerTask {
public void run() {
// call the method to change the value of label for timer/clock here
System.out.println("Beep! One second");
}
}
Game Clock from 00 : 00
to 12 : 00
Lets say the first 00
is textfieldA and the second 00
is textfieldB
So, essentially [textfieldA] : [textfieldB]
method countEverySecond() {
get value from textfieldB, lets assign this in variable valueB
increment valueB by 1
if valueB > 60 {
get valuefrom textfieldA, lets assign this in variable valueA
increment valueA by 1
if valueA > 12 {
stop timer
}
}
}
@iserifith Closed as the basic goals are achieved.
Continue to the next issue
There should be 2 labels to show clock
Note : The value is incremented by the second using the timer.