OO Programming with Java


Events

  1. Integrate to Timer 's class:
private List<TimerListener> listeners = new ArrayList();
public void addTimerListener(TimerListener l) 
{ listeners.add(l); }
public void removeTimerListener(TimerListener l) 
{ listeners.remove(l); }
protected void fireTic() 
{ for(TimerListener l : listeners) 
    l.tic(new TimerEvent(this)); } 

// update 'run'
try {
  fireTic();
  Thread.sleep(delay );
} catch (InterruptedException e) {
  e.printStackTrace();
} } 

8 - 12