/** Reacts to the timer's action events. */
    public void actionPerformed(ActionEvent e) {
      if (ADJUSTTIMER) {
        long time = System.currentTimeMillis();

        if (lastCall > 0) { // adjust nextDelay
          // XXX maybe should cache this after a while
          // actual = time - lastCall
          // difference = actual - interval
          // nextDelay = previousDelay - difference
          //          = previousDelay - (time - lastCall - interval)
          int nextDelay = (int) (previousDelay - time + lastCall + getRepaintInterval());
          if (nextDelay < MINIMUM_DELAY) {
            nextDelay = MINIMUM_DELAY;
          }
          timer.setInitialDelay(nextDelay);
          previousDelay = nextDelay;
        }
        timer.start();
        lastCall = time;
      }

      incrementAnimationIndex(); // paint next frame
    }