iserifith / ScoreBoard

0 stars 0 forks source link

Add timer and some labels to show clock/counter #6

Closed mrafsyam closed 8 years ago

mrafsyam commented 8 years ago

There should be 2 labels to show clock

  1. Game clock - this is (the bigger clock) limited from 00:00 (0 minutes and 0 second) to 12:00 (12 minutes)
  2. Shot clock - this is (the smaller clock) limited from 00 (0 seconds) to 24 (24 seconds)

Note : The value is incremented by the second using the timer.

main

mrafsyam commented 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");
   }
}
mrafsyam commented 8 years ago

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 commented 8 years ago

screenshot from 2016-09-26 00 01 14

mrafsyam commented 8 years ago

@iserifith Closed as the basic goals are achieved.

Continue to the next issue