Parameterize Pie Drawing New Pie Another Pie

// filename: PieVars.java
import java.awt.*;
import java.applet.*;

public class PieVars extends Applet
{
  int diameter;    // where on the circle to start drawing
  int angle;	   // this looks like the original
  int bandWidth;

  Color bColor,lcColor,rcColor;

  public void drawPie(Graphics g, int x, int y,
		      Color colorBand, Color colorProp1, Color colorProp2)
  {
    // draw the edge
    g.setColor(colorBand);
    g.fillOval(x , y, (7*diameter)/5, (7*diameter)/5);

    // the slices of the first color
    g.setColor(colorProp1);
    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(colorProp2);
    g.fillArc(x + bandWidth, y + bandWidth,
		    diameter, diameter, angle + 90, 90);
    g.fillArc(x + bandWidth, y + bandWidth,
		    diameter, diameter, angle + 270, 90);
  }

  public void paint(Graphics g)

  {
    diameter = Integer.parseInt(getParameter("diameter"));

    angle = Integer.parseInt(getParameter("angle"));

    bColor = new Color(Integer.parseInt(getParameter("bColor"),16));
    lcColor = new Color(Integer.parseInt(getParameter("lcColor"),16));
    rcColor = new Color(Integer.parseInt(getParameter("rcColor"),16));

    bandWidth = diameter / 5;

    drawPie(g, 	Integer.parseInt(getParameter("xCord")), 
		Integer.parseInt(getParameter("yCord")),
		bColor,lcColor,rcColor);
  }
}

Previou page Next page