I am having problems with my piechart. I have everything that I am supposed to I think. It won't display in my JPanel. Could you please point me in the right direction.
Code:
P = Q;//sets loop
month++;
//String showAmort = twoPlaces.format(H + C + Q);
//amortScroll(showAmort);
//ta.append("Month " + month);
ta.append("Interest Paid: " + twoPlaces.format(H));
ta.append("\tPrincipal Paid: " + twoPlaces.format(C));
ta.append("\tNew Balance: " + twoPlaces.format(Q) + "\n");
}
}
public void Calculations_manual() //performs the calculations from user input
{
double P = Double.parseDouble(PField.getText());
double I = Double.parseDouble(IField.getText());
double L = Double.parseDouble(LField.getText());
double J = (I / (12 * 100));//monthly interest rate
double N = (L * 12);//term in months
double M = (P * J) / (1 - Math.pow(1 + J, - N));//Monthly Payment
String showPayment = twoPlaces.format(M);
payment.setText(showPayment);
int month = 1;
while (month <= N)
{
//performs the calculations for the amortization
double H = P * J;//current monthly interest
double C = M - H;//monthly payment minus monthly interest
double Q = P - C;//new balance
P = Q;//sets loop
month++;
//String showAmort = twoPlaces.format(H + C + Q);
//amortScroll(showAmort);
//ta.append("Month " + month);
ta.append("Interest Paid: " + twoPlaces.format(H));
ta.append("\tPrincipal Paid: " + twoPlaces.format(C));
ta.append("\tNew Balance: " + twoPlaces.format(Q) + "\n");
}
}
// resets GUI for another calculation
public void reset ()
{
PField.setText(null);
payment.setText(null);
ta.setText(null);
LField.setText(null);
IField.setText(null);
}
// ends GUI and exits program
public void end()
{
System.exit(0);
}
public class PieChart extends JComponent {
// Class to hold a value for a slice
class PieSlice
{
//private variables
double value;
Color color;
public PieSlice(double value, Color color)
{
this.value = value;
this.color = color;
}//end Constructor
} //end class PieSlice
//private variable slices are array of PieSlice
PieSlice[] slices = new PieSlice[2];
//constructor
PieChart(double C, double H)
{
slices[0] = new PieSlice(C, Color.red);
slices[1] = new PieSlice(H, Color.green);
setVisible(true);
}
// This method is called whenever the contents needs to be painted
public void paintComponent(Graphics g) {
// Draw the pie
this.drawPie((Graphics2D)g, getBounds(), slices);
}
// slices is an array of values that represent the size of each slice.
public void drawPie(Graphics2D g, Rectangle area, PieSlice[] slices)
{
// Get total value of all slices
double total = 0.0;
for (int p=0; p<slices.length; p++) {
total += slices[p].value;
}
// Draw each pie slice
double curValue = 0.0;
int startAngle = 0;
for (int p=0; p<slices.length; p++)
{
// Compute the start and stop angles
startAngle = (int)(curValue * 360 / total);
int arcAngle = (int)(slices[p].value * 360 / total);
// Ensure that rounding errors do not leave a gap between the first and last slice
if (p == slices.length-1) {
arcAngle = 360 - startAngle;
} //end if
// Set the color and draw a filled arc
g.setColor(slices[p].color);
g.fillArc(area.x, area.y, 200, 200, startAngle, arcAngle);
RenderingHints renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setRenderingHints(renderHints);
//int border=10;
//Ellipse2D.Double elb = new Ellipse2D.Double(area.x - border/2, area.y - border/2, pieWidth + border, pieHeight + border);
//g.fillArc(area.x, area.y, area.width, area.height, startAngle, arcAngle);
curValue += slices[p].value;
} //end for
}//end drawPie
public void resetPieChart(double capital, double interest)
{
slices[0] = new PieSlice(capital, Color.red);
slices[1] = new PieSlice(interest, Color.green);
this.repaint();
}//end resetPieChart
}//end class PieChart
public static void main(String[] args)
{
MortCalcWeek5p app = new MortCalcWeek5p();
app.pack();
}//end main
}//end the program
Thank you in advance for any help you may be.
Thanks,
Christine