// Timer.java
// Timer class which implements an ActionEvent
// unicaster protocol.
//
// Fintan Culwin, v0.1, Dec 1998.
// Modified by Daniel Farinha January 1999

import java.awt.event.*;


public class Timer extends Thread { 

private int            theTime     = 0;
private ActionListener itsListener = null;


   public Timer() { 
      super();
      theTime =0;
   } // End Timer constructor.


   public void run() { 
      while ( true) { 
         try { 
           this.sleep( 500);
         } catch (InterruptedException exception) { 
            // Do nothing. 
         } // End try/ catch
         theTime++;

         if ( itsListener != null) { 
         String timeString = new String( 
                         new Integer( theTime).toString());

         ActionEvent theEvent = new ActionEvent( this,
                                    ActionEvent.ACTION_PERFORMED,
                                    timeString);
            itsListener.actionPerformed( theEvent);
         } // End if.        
      } // end while.
   } // End run.


   public synchronized void resetTime() { 
      theTime =0;
   } // End resetTime;


   public void addActionListener( ActionListener listener) 
                  throws java.util.TooManyListenersException { 
      if ( itsListener == null) { 
         itsListener = listener;
      } else { 
         throw new java.util.TooManyListenersException();
      } // End if.
   } // End addActionListener.


   public void removeActionListener( ActionListener listener) { 
      if ( itsListener == listener) { 
         itsListener = null;
      } // End if.
   } // End removeActionListener.

} // End Timer.