Add graphics in the form of a chart to an Amortization/Mortgage program

How can I modify program  to read the interest rates to fill the array from a sequential file and display /add graphics in the form of a chart."

This What  i Have so far:

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

//Declared program AmorSchedule class
public class  Schedule2 extends JFrame implements ActionListener,ItemListener { // Creates

//Declared calculation varibles and strings

int term = 0;

double principal = 0;

double rate = 0;

double monthlyPayment = 0;

double interest = 0;

String mPrincipal[] = {"200000", "250000","300000"};

String mTerm[] = { "7", "15", "30" };

String mInterst[] = { "5.35%", "5.50%", "5.75%" };

//The purpose of this program is to create an Amortization Paymment Schedule
//The functions below will initiate display panel
// Format panel frame and preselect label buttons.
JPanel row1 = new JPanel();
JLabel mortgage_label = new JLabel("Wonda's Amortization Schedule Calculator",
JLabel.CENTER);//This function creates title bar in Gui panel

JPanel row2 = new JPanel(new GridLayout(1, 2));

JLabel principal_label = new JLabel("Mortgage Principal $", JLabel.LEFT);

JTextField principal_txt = new JTextField(10);//Set text size parameters

JPanel row3 = new JPanel(new GridLayout(1, 2));

JLabel term_label = new JLabel("Mortgage Term (Yrs)", JLabel.LEFT);

JTextField term_txt = new JTextField(10);

JPanel row4 = new JPanel(new GridLayout(1, 2));

JLabel rate_label = new JLabel("Interest Rate (%)", JLabel.LEFT);

JTextField rate_txt = new JTextField(10);

//This will display buttons just above text area output
JPanel radioPanel = new JPanel();
Container contentPane=getContentPane();
JComboBox jc=new JComboBox();

JPanel row5 = new JPanel(new GridLayout(1, 2));

JLabel payment_label = new JLabel("Monthly Payment $", JLabel.LEFT);

JTextField payment_txt = new JTextField(10);

// The function below will set and aling button lay out panel
JPanel button = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 12));

JButton clearButton = new JButton("Clear");

JButton exitButton = new JButton("Exit");

JButton calculateButton = new JButton("Calculate");

JButton nop=new JButton("# of Payment");

JButton amt = new JButton("Amount");

JButton interestb = new JButton("Interest");

JButton balanceb = new JButton("Balance");

// The is will display number of payments,amount due after payment
//interest rate and pay off balance in text box  area
JTextArea displayArea = new JTextArea(100,135);//Text are paramenters set

JScrollPane scroll = new JScrollPane(displayArea);

//Container method componets
public  Schedule2()

super("Wonda's Amortization Schedule ");
setSize(600,800);//Set initial container program diameter
Container pane = getContentPane();

Border rowborder = new EmptyBorder(3, 10, 3, 10);

row1.setMaximumSize(new Dimension(7500, row1.getMinimumSize().height));

row2.setMaximumSize(new Dimension(7500, row2.getMinimumSize().height));

row3.setMaximumSize(new Dimension(7500, row3.getMinimumSize().height));

row4.setMaximumSize(new Dimension(7500, row4.getMinimumSize().height));

contentPane.setLayout(new FlowLayout(FlowLayout.CENTER));
jc.addItem("Select number of years and interest rate from this drop down");
jc.addItem("200000 7 Years at 5.35%");//Array for first calculation
jc.addItem("250000 15 Years at 5.50%");//Array for second calculation
jc.addItem("300000 30 Years at 5.75%");//Array for third calculation

payment_txt.setEnabled(false); // This function will set payment amount uneditable
row5.setMaximumSize(new Dimension(7500, row5.getMinimumSize().height));

//The function bellow will set intial astetic look and color to button
//text are  back ground
calculateButton.setBackground(;//This command will add button color background

clearButton.setBackground( Color.yellow);//This command will add button color background

exitButton.setBackground(;//This command will add button color background

displayArea.setBackground( Color.white);//This command will set text color background

JPanel button1 = new JPanel(new FlowLayout(FlowLayout.CENTER,62, 8));//This will set button parameters over text area

button.setMaximumSize(new Dimension(7500, button.getMinimumSize().height));

scroll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

// Event handling codes for buttons, dropped down menus, mouse events and calcualtion
// This section is to add listeners
jc.addItemListener(this);// This listner add drop down box

//The function below will auto populate upon drop down selection
//display terms in years and interest rate
//in designated text field set to calculate at user manual input
public void itemStateChanged(ItemEvent ie){
if(ie.getItem()== "200000 7 Years at 5.35%"){
principal  = 200000;
rate = 5.35;
term = 7;
} else if (ie.getItem()== "250000 15 Years at 5.50%") {
principal  = 250000;
rate = 5.50;
term = 15;
} else if (ie.getItem()== "300000 30 Years at 5.75%") {
principal  = 300000;
rate = 5.75;
term = 30;

//Declared action listner method will calculate upon
//button selection, clear or exit program upon selecting desired
//action determined by end user
public void actionPerformed(ActionEvent event)

Object source = event.getSource();
if (source instanceof AbstractButton) {

if (event.getSource() == calculateButton) {

try {
////Validate users input
//If no numerical value entered by end user
//this function will display error message notifying
//end user of invalid entry prompting to try again
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(null, "Amount Entered Must Be A Value More Than Zero. This Is An Invaild Entry! Please Try Again",

if (event.getSource() == clearButton) {

if (event.getSource() == exitButton) {

//This function below will calculate payments
public void Payment()

// function below will calculate principal loan      
double principal = Double.parseDouble(principal_txt.getText()); // Principal

// This function below will calculate rate and term
float rate1 = Float.parseFloat((String) rate_txt.getText()); // Interest
double rate = rate1 / 100;
int term = Integer.parseInt((String) term_txt.getText()); // Length of Loan

// Monthly interst rate
double perMonthRate = rate / 12;

// Number of months over which loan is amortized
double termMonths = term * 12;

//Program calculation formula

double monthlyPayment = principal
* (perMonthRate / (1 - Math.pow((1 + perMonthRate), (-termMonths))));

//Program varibles formatted in $ currency,% for monthly interest rates
// and mortgage interest rates based on terms and condition of year
DecimalFormat df = new DecimalFormat("\u00A4#,##0.00"); //to transcribe to currency
DecimalFormat pf = new DecimalFormat("#,##0.00%"); //to transcribe to percentage
DecimalFormat mi = new DecimalFormat("#,##0.000%"); //to transcribe to percentage
payment_txt.setText("" + df.format(monthlyPayment));

// Amoritization variables declared to
//set interest paid on initial loan amount,
//prinicpal applied to each payment
//ultimately displaying total principal owed after payment
double interestPaid = 0;  
double monthlyPrincipal = 0;
double principalBalance = principal;

//Payment number set up
int paymentNumber = 1;
int temp=1;

// This loop increments the term length in years based on specified selection
for (int y = 1; y <= term; y++) { // This functon will intiate outer loop

// Inserts a blank line

// This loop will  calculate and display the amortization payment schedule
for (int m = 0; m < 12; m++) { // This funtione will initiate inner loop

interestPaid = principalBalance * perMonthRate;
monthlyPrincipal = monthlyPayment - interestPaid;
principalBalance = principalBalance - monthlyPrincipal;
displayArea.append("Payment " + paymentNumber + "\t\t"
+ df.format(monthlyPrincipal) + "\t\t" + df.format(interestPaid)
+ "\t\t" + df.format(principalBalance) + "\n");
//This loop will hesitate program  five second before calculation begins
      catch (InterruptedException e)



//End of declared main method
public static void main(String[] arguments) {

 Schedule2 mgt = new  Schedule2();


Help I need to complete this today!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

to create charts use JFreeChart

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
There are plenty of open-source reporting and charting tools available in Java which can be used:
Mayank SAssociate Director - Product EngineeringCommented:
>> ie.getItem()== "250000 15 Years at 5.50%"

You need to use equals () while comparing Strings everywhere:

ie.getItem().equals ( "250000 15 Years at 5.50%" )
WondaBriagarAuthor Commented:
I am still confused I tried to substitute above code only to get compiling  error
Mayank SAssociate Director - Product EngineeringCommented:
You must have substituted it wrongly. Post one of the lines where you get that error.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.