// filename: Pie.java
import java.awt.*;
public class Pie
{
int x, y;
int diameter;
int angle;
int bandWidth;
Color bColor,lcColor,rcColor;
public Pie(int x, int y, int diameter, int angle, int bandWidth,
Color bColor, Color lcColor, Color rcColor)
{
this.x = x;
this.y = y;
this.diameter = diameter;
this.angle = angle;
this.bandWidth = bandWidth;
this.bColor = bColor;
this.lcColor = lcColor;
this.rcColor = rcColor;
}
public void drawPie(Graphics g)
{
// draw the edge
g.setColor(bColor);
g.fillOval(x , y, (7*diameter)/5, (7*diameter)/5);
// the slices of the first color
g.setColor(rcColor);
g.fillArc(x + bandWidth, y + bandWidth,
diameter, diameter, angle, 90);
g.fillArc(x + bandWidth, y + bandWidth,
diameter, diameter, angle + 180, 90);
// the slices of the second color
g.setColor(lcColor);
g.fillArc(x + bandWidth, y + bandWidth,
diameter, diameter, angle + 90, 90);
g.fillArc(x + bandWidth, y + bandWidth,
diameter, diameter, angle + 270, 90);
}
}
//filename: PieApplet.java
import java.awt.*;
import java.applet.Applet;
public class PieApplet extends Applet {
public Pie p1;
public void init() {
p1 = new Pie(100,100,300,0,60,Color.black,Color.blue,Color.white);
}
public void paint ( Graphics g ) {
for (int i=0;i<10000 ; i++)
{
p1.angle = i;
p1.drawPie(g);
}
}
}