Academic Java    Java Tutorial  >  Applets  >  drawArc() fillArc()

drawArc() fillArc() Example

Java drawArc() fillArc EXAMPLE output The first four parameters of drawArc() and fillArc() specify a rectangle with x, y coordinates at top-left of it. The center of the rectangle is the center of the arc.

The next two are startAngle and arcAngle. The resulting arc begins at startAngle and extends for arcAngle degrees. Angles are interpreted such that 0 degrees is at the 3 o'clock position. Positive values indicate counter-clockwise rotation, negative values go clockwise.
// drawArc() fillArc() Example
import java.awt.*;
import javax.swing.*;

class DrawArcExample extends JApplet {

   public void paint(Graphics g) {
      super.paint(g);

      int x=75, y=100, w=150, h=100;

      g.setColor(Color.blue);
      g.fillArc(x,y,w,h,0,90);

      g.setColor(Color.cyan);
      g.fillArc(x,y,w,h,0,-90);

      g.setColor(Color.magenta);
      g.fillArc(x,y,w,h,-90,-90);

      g.setColor(Color.orange);
      g.fillArc(x,y,w,h,90,90);

      g.setColor(Color.black);
      while(h>10) {
         g.drawArc(x,y,w,h,0,360);
         x+=10; y+=10; w-=20; h-=20;
      }

   }
}


* drawArc() fillArc() Examples