import java.awt.*;
import javax.swing.*;

public class PieChartWriter extends JFrame {
    private static String[] labels = {"","","","","",""};  // new String[6];
    private static int[] amounts = {0,0,0,0,0,0};          //new int[6];
    private static Color[] pieColors = new Color[6];
    private static int one_percent = 0;
    private static int ialt = 0;
    
    /** Constructer method for PieChartWriter */
    public PieChartWriter() {
	setSize(350,200);
	setLocation(50,100);
	setBackground(Color.white);
	setVisible(true);
    }
    
    /** paint uses a for-loop to loop through the values, strings, 
     * colours stored in the arrays specified (labels,
     * amounts and colors).The for loops is also used to 
     * increment the value of the angle by which the slices
     * are drawn.
     * @param g - the graphic pen that paints
     */
    public void paint(Graphics g) {
	g.drawOval(50 , 50, 100, 100);
	one_percent = 360/(amounts[0] +
			   amounts[1] +
			   amounts[2] +
			   amounts[3] +
			   amounts[4] +
			   amounts[5]);
	
	for (int i = 0 ; i < 5 ; i = i+1) {
	    g.setColor(pieColors[i]);
	    g.fillArc(50,50,100,100, ialt, one_percent * amounts[i]);
	    g.drawString(labels[i],175,70+(i*25));
	    ialt = ialt + (one_percent * amounts[i]);
	}
	
    }
    
    /** setSlice1 draws the first slice of the chart
     * @param label - the label is printed to the right of the circle
     * @param amount - is the amount of the slice = the relative size
     * @param c - the color of the label and the slice 
     */
    
    public void setSlice1(String label, int amount, Color c) {
        pieColors[0] = c;
	amounts[0] = amount;
	labels[0] = label;
    }
    
    /** setSlice2 draws the first slice of the chart
     * @param label - the label is printed to the right of the circle
     * @param amount - is the amount of the slice = the relative size
     * @param c - the color of the label and the slice 
     */  
    public void setSlice2(String label, int amount, Color c) {
        pieColors[1] = c;
	amounts[1] = amount;
	labels[1] = label;	
    }
    
    /** setSlice3 draws the first slice of the chart
     * @param label - the label is printed to the right of the circle
     * @param amount - is the amount of the slice = the relative size
     * @param c - the color of the label and the slice 
     */
    public void setSlice3(String label, int amount, Color c) {
        pieColors[2] = c;
	amounts[2] = amount;
	labels[2] = label;	
    }
    
    /** setSlice4 draws the first slice of the chart
     * @param label - the label is printed to the right of the circle
     * @param amount - is the amount of the slice = the relative size
     * @param c - the color of the label and the slice 
     */
    public void setSlice4(String label, int amount, Color c) {
        pieColors[3] = c;
	amounts[3] = amount;
	labels[3] = label;	
    }
    
    /** setSlice5 draws the first slice of the chart
     * @param label - the label is printed to the right of the circle
     * @param amount - is the amount of the slice = the relative size
     * @param c - the color of the label and the slice 
     */
    public void setSlice5(String label, int amount, Color c) {
        pieColors[4] = c;
	amounts[4] = amount;
	labels[4] = label;	
    }
    
    /** setSlice6 draws the first slice of the chart
     * @param label - the label is printed to the right of the circle
     * @param amount - is the amount of the slice = the relative size
     * @param c - the color of the label and the slice 
     */
    public void setSlice6(String label, int amount, Color c) {
        pieColors[5] = c;
	amounts[5] = amount;
	labels[5] = label;	
    }
}
