コード例 #1
0
  /**
   * Sets the index of the current animation frame to the specified value and requests that the
   * progress bar be repainted. Subclasses that don't use the default painting code might need to
   * override this method to change the way that the <code>repaint</code> method is invoked.
   *
   * @param newValue the new animation index; no checking is performed on its value
   * @see #incrementAnimationIndex
   * @since 1.4
   */
  protected void setAnimationIndex(int newValue) {
    if (animationIndex != newValue) {
      if (sizeChanged()) {
        animationIndex = newValue;
        maxPosition = 0; // needs to be recalculated
        delta = 0.0; // needs to be recalculated
        progressBar.repaint();
        return;
      }

      // Get the previous box drawn.
      nextPaintRect = getBox(nextPaintRect);

      // Update the frame number.
      animationIndex = newValue;

      // Get the next box to draw.
      if (nextPaintRect != null) {
        boxRect = getBox(boxRect);
        if (boxRect != null) {
          nextPaintRect.add(boxRect);
        }
      }
    } else { // animationIndex == newValue
      return;
    }

    if (nextPaintRect != null) {
      progressBar.repaint(nextPaintRect);
    } else {
      progressBar.repaint();
    }
  }