Class UDCSimpleTimer

java.lang.Object
com.nt.udc.util.UDCSimpleTimer

public class UDCSimpleTimer extends Object
This is a simple timer that can be used to periodically cause a specific action to be performed on an object listening to the timer.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UDCSimpleTimer(int delay, ActionListener listener)
    Construct the timer, providing the object for which an action will be performed and the amount of time (in milliseconds) between those actions.
    UDCSimpleTimer(int delay, ActionListener listener, int repeat)
    Construct the timer, providing the object for which an action will be performed and the amount of time (in milliseconds) between those actions.
    UDCSimpleTimer(long delay, ActionListener listener)
     
    UDCSimpleTimer(long delay, ActionListener listener, int repeat)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    boolean
    Indicates whether the timer is running
    void
    Reset the timer.
    void
    restart(int delay)
    Reset the timer.
    void
    setRepeats(boolean repeat)
    If repeat is false, the timer to send actionPerformed() to its listener only once, and then stop.
    void
    skipToEvent(boolean skip)
    Causes or prevents the current timer iteration to/from proceeding to the next event.
    void
    Start the timer
    void
    Stop the timer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • UDCSimpleTimer

      public UDCSimpleTimer(int delay, ActionListener listener)
      Construct the timer, providing the object for which an action will be performed and the amount of time (in milliseconds) between those actions. Once the start() method has been called, the timer will continue to cycle until the stop() method is called.
      Parameters:
      delay - The number of milliseconds this timer will sleep between calls to the ActionListener.
      listener - An ActionListener object which will have its actionPerformed() method called when the timer's 'delay' time has expired.
    • UDCSimpleTimer

      public UDCSimpleTimer(long delay, ActionListener listener)
    • UDCSimpleTimer

      public UDCSimpleTimer(int delay, ActionListener listener, int repeat)
      Construct the timer, providing the object for which an action will be performed and the amount of time (in milliseconds) between those actions. Once the start() method has been called, the timer will cycle as many times as indicated by the value of repeat. A value of zero (0) indicates the timer should run until the stop() method is called.
      Parameters:
      delay - The number of milliseconds this timer will sleep between calls to the ActionListener.
      listener - An ActionListener object which will have its actionPerformed() method called the timer's 'delay' time has expired.
      repeat - Number of times this timer will run.
    • UDCSimpleTimer

      public UDCSimpleTimer(long delay, ActionListener listener, int repeat)
  • Method Details

    • isRunning

      public boolean isRunning()
      Indicates whether the timer is running
    • setRepeats

      public void setRepeats(boolean repeat)
      If repeat is false, the timer to send actionPerformed() to its listener only once, and then stop. This method exists to mimic the javax.swing.Timer class. However, a finer granularity can be achieved by setting the repeat value via the constructor.
    • start

      public void start()
      Start the timer
    • restart

      public void restart()
      Reset the timer. If the timer is running, the current cycle will be interrupted, the designated action on the ActionListener will not be performed and the next cycle will begin, provided the 'repeat count' has not been exceeded.
      If the timer is not running, it will be started;
    • skipToEvent

      public void skipToEvent(boolean skip)
      Causes or prevents the current timer iteration to/from proceeding to the next event. If set to true, then the current iteration will proceed to the next event. If the timer is sleeping, it will wake up. If the timer is not sleeping, then it will skip the NEXT timer period, and generate the next event immediately. If set to false, then the next timer iteration will proceed normally, waiting according to the specified delay. This method will most likely use the "true" setting. However, "false" may be used in the implemented "actionListener" so that its "actionPerformed()" method will not be called immediately.
      Parameters:
      skip - true, to skip the NEXT timer, or interrupt the current timer. false, to proceed as normal
    • restart

      public void restart(int delay)
      Reset the timer. If the timer is running, the current cycle will be interrupted, the designated action on the ActionListener will not be performed and the next cycle will begin, provided the 'repeat count' has not been exceeded.
      If the timer is not running, it will be started;
      Parameters:
      delay - Resets the delay of the timer to the given value
    • stop

      public void stop()
      Stop the timer. The current cycle will be interrupted and the designated action on the ActionListener will not be performed.
    • isHealthy

      public boolean isHealthy()