import javax.swing.*;
import java.awt.*;
/**
* Created by S1195552 on 4/7/14.
*/
public class PanelChart extends JPanel {
private double Boston;
private double Miami;
private double Dallas;
private double StLouis;
private double KansasCity;
private double Seattle;
private double LosAngeles;
private double total;
private Graphics g;
public void paintComponent(Graphics g)
{
super.paintComponent(g);
this.g = g;
drawChart();
}
public void setPopulation(double boston, double miami, double dallas, double stLouis, double kansasCity, double seattle, double losAngeles) {
Boston = boston;
Miami = miami;
Dallas = dallas;
StLouis = stLouis;
KansasCity = kansasCity;
Seattle = seattle;
LosAngeles = losAngeles;
this.total = this.Boston +
this.Miami +
this.Dallas +
this.StLouis +
this.KansasCity +
this.Seattle +
this.LosAngeles;
repaint();
}
public void drawChart()
{
int pctBoston = (int)(Boston/total*100);
int pctMiami = (int)(Miami/total*100);
int pctDallas = (int)(Dallas/total*100);
int pctStLouis = (int)(StLouis/total*100);
int pctKansasCity = (int)(KansasCity/total*100);
int pctSeattle = (int)(Seattle/total*100);
int pctLosAngeles = (int)(LosAngeles/total*100);
int factor = 55;
g.setColor(Color.magenta);
//g.fillRect(25, factor * 1 - 15, pctBoston * 3, 10);
g.fillOval(25, factor * 1 - 15, pctBoston * 3, 10);
//g.drawOval();
g.setColor(Color.yellow);
g.fillRect(25,factor * 2-15,pctMiami*3,10);
g.setColor(Color.gray);
g.fillRect(25,factor * 3-15,pctDallas*3,10);
g.setColor(Color.green);
g.fillRect(25,factor * 4-15,pctStLouis*3,10);
g.setColor(Color.red);
g.fillRect(25,factor * 5-15,pctKansasCity*3,10);
g.setColor(Color.red);
g.fillRect(25,factor * 5-15,pctSeattle *3,10);
g.setColor(Color.red);
g.fillRect(25,factor * 5-15,pctLosAngeles*3,10);
}
}