import java.awt.*;

public class PieDisplay extends java.applet.Applet {

	protected int maxCategories=5;
	protected int catCount = 0;
	protected String categories[] = new String[maxCategories];
	protected int amount[] = new int[maxCategories];
	protected Color fillColor[] = {Color.green, Color.red, Color.blue, Color.black, Color.yellow};
	protected int total = 0;

	public void init(){
        String att = getParameter("categories");
        int i = 0;
        while (att.length()>0){
			 if (att.indexOf(' ') > 0){
		          categories[i] = att.substring(0, att.indexOf(' '));
		          att = att.substring(att.indexOf(' '));
		          att = att.trim();
		     }else{
				  categories[i] = att;
				  att = "";
		     }
		     i++;
	    }
	    catCount = i;
	    for (i=0;i<catCount;i++){
			amount[i] = Integer.parseInt(getParameter(categories[i]));
			total += amount[i];
	    }
    }

    public void paint(Graphics g){
		int angle=0;
		for (int i=0;i<catCount;i++){
			g.setColor(Color.black);
			g.drawString(categories[i],20, (i+1)*20 + 350);
			g.setColor(fillColor[i]);
			g.fillRect(100, (i+1)*20 + 340,10,10);
			double temp = amount[i];
			temp = temp/(double)total;
			g.fillArc(30,30,250,250, angle, (int)(temp *360));
			angle = angle + (int)(temp * 360);
	    }
    }
}