Example #1
0
  /** paints the Spinner */
  public void paint(Graphics g) {
    int start_angle = 90;
    int done_angle = (int) (percentDone * 360);

    g.setColor(getBackground());
    g.fillArc(3, 3, getSize().width - 8, getSize().height - 8, 0, 360);

    g.setColor(getForeground());
    g.fillArc(3, 3, getSize().width - 8, getSize().height - 8, start_angle, done_angle);

    g.setColor(Color.black);
    g.drawArc(3, 3, getSize().width - 8, getSize().height - 8, 0, 360);
  }
Example #2
0
  /**
   * Draws a "solid" arc which will look either like a pie wedge or Pac-man.<br>
   * A FILLED ARC is a "piece" of a SOLID OVAL.<br>
   * The first 5 parameters (g and 4 ints) are the same as drawOval.<br>
   * There are 2 additional parameters for the starting degree value and finishing degree of the
   * arc. <br>
   * 0 degrees is at the 12:00 position and the degrees progress in a CLOCKWISE fashion. <br>
   * (90 degrees is at 3:00, 180 degrees is at 6:00, 270 degrees is at 9:00, 360 degrees is back at
   * 12:00).
   */
  public static void fillArc(
      Graphics g, int centerX, int centerY, int hRadius, int vRadius, int start, int finish) {
    int hDiameter = 2 * hRadius;
    int vDiameter = 2 * vRadius;

    if (finish < start) finish += 360;
    int newStart = 90 - start; // shifts starting position from 3:00 to 12:00
    int newFinish =
        start
            - finish; // as oppose to finish-start.  Subtracting backwards changes from
                      // counter-clockwise to clockwise.

    g.fillArc(centerX - hRadius, centerY - vRadius, hDiameter, vDiameter, newStart, newFinish);
  }