Package doodlepad

Class Timer

java.lang.Object
doodlepad.Timer

public class Timer extends Object
A class that implements a stand-alone, non-graphical Timer object. Provides for multiple Timers in a single program.
  • Constructor Details

    • Timer

      public Timer()
      Nullary constructor setting default tick rate
    • Timer

      public Timer(double tps)
      Timer constructor with initial tick rate parameter
      Parameters:
      tps - Ticks per second
  • Method Details

    • setTickRate

      public final void setTickRate(double tps)
      Set the rate at which to fire onTick events
      Parameters:
      tps - Ticks per second
    • getTickRate

      public final double getTickRate()
      Return the current rate at which the timer ticks
      Returns:
      A double indicating ticks per second.
    • startTimer

      public void startTimer()
      Start the timer firing onTick events.
    • stopTimer

      public void stopTimer()
      Stop timer
    • toggleTimer

      public void toggleTimer()
      Toggle the state of the timer. Started/Stopped.
    • isRunning

      public boolean isRunning()
      Determine if the timer is running
      Returns:
      True or false indicating if the timer is running.
    • setStartHandler

      public void setStartHandler(Timer.TimerEventHandler handler)
      Assign an onStart event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setTickHandler

      public void setTickHandler(Timer.TimerEventHandler handler)
      Assign an onTick event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • setStopHandler

      public void setStopHandler(Timer.TimerEventHandler handler)
      Assign an onStop event handler using a method reference.
      Parameters:
      handler - Method reference to an event handler
    • onTick

      public void onTick(long when)
      A method that can be overridden to handle the timer`s tick event. The timer tick rate is set with the setTickRate() method. The timer is started by invoking the startTimer() method. The timer is stopped by invoking the stopTimer() method.
      Parameters:
      when - The difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.
    • onStart

      public void onStart(long when)
      A method that can be overridden to handle the timer`s start event. The timer is started by invoking the startTimer() method.
      Parameters:
      when - The difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.
    • onStop

      public void onStop(long when)
      A method that can be overridden to handle the timer`s stop event. The timer is stopped by invoking the stopTimer() method.
      Parameters:
      when - The difference in milliseconds between the timestamp of when this event occurred and midnight, January 1, 1970 UTC.
    • addStartListener

      public void addStartListener(TimerEventListener o)
      Add object to the list of items that are notified on Timer start action.
      Parameters:
      o - An object that implements the TimerTickListener interface.
    • removeStartListener

      public void removeStartListener(TimerEventListener o)
      Remove object from Timer's start action listener list.
      Parameters:
      o - The TimerEventListener object to be removed.
    • addTickListener

      public void addTickListener(TimerEventListener o)
      Add object to the list of items that are notified on Timer's tick action.
      Parameters:
      o - An object that implements the ActionListener interface.
    • removeTickListener

      public void removeTickListener(TimerEventListener o)
      Remove object from Timer's tick action listener list.
      Parameters:
      o - The ActionListener object to be removed.
    • addStopListener

      public void addStopListener(TimerEventListener o)
      Add object to the list of items that are notified on Timer stop action.
      Parameters:
      o - An object that implements the TimerEventListener interface.
    • removeStopListener

      public void removeStopListener(TimerEventListener o)
      Remove object from Timer's start action listener list.
      Parameters:
      o - The TimerTickListener object to be removed.
    • finalize

      protected void finalize() throws Throwable
      Stop internal Timer when garbage collected.
      Overrides:
      finalize in class Object
      Throws:
      Throwable - May throw exceptions