I guess I'll just post what my intent is.
Write a program that creates a loan amortization table. The user of the program will supply values for Initial Loan Principal, Annual Percentage Rate and Monthly Payment. The program should print out the appropriate amortization table including the number of Monthly Payments and the Total Interest paid for the life of the loan. The program should allow multiple runs (up to 4 different versions) of the table process and should allow the user to compare runs in a tabular format
My idea was to make a null layout page that would be similar to something like this
Edit: This is how I want my final outcome to act like:
http://www.1728.com/mortpmts.htmSo I made this already
CODE
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
public class Program1 {
//Sets the controls needed.
static JFrame frame1;
static Container pane;
static JLabel lblPrincipal, lblAnnualInterestRate, lblMonthlyPayment,lblNumMonthlyPay, lblTotalInterestPaid;
static JButton btnCalculate;
static JTextField txtPrincipal, txtAnnualInterestRate, txtMonthlyPayment,txtNumMonthlyPay, txtTotalInterestPaid;
static Insets insets;
public static void createControls ()
{
//Create controls
btnCalculate = new JButton ("Calculate");
lblPrincipal = new JLabel ("Principal");
lblAnnualInterestRate = new JLabel ("Annual Interest Rate");
lblMonthlyPayment = new JLabel ("Monthly Payment");
lblNumMonthlyPay = new JLabel ("Number of Monthly Payments");
lblTotalInterestPaid = new JLabel ("Total Interest Paid");
txtPrincipal = new JTextField (10);
txtAnnualInterestRate = new JTextField ( 10);
txtMonthlyPayment = new JTextField (10);
txtNumMonthlyPay = new JTextField(10); //I want there to be an output here.
txtTotalInterestPaid = new JTextField(10);//I want there to be an output here.
}
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
Program1 loan = new Program1();
//Set Look and Feel
try {UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}
catch (ClassNotFoundException e) {}
catch (InstantiationException e) {}
catch (IllegalAccessException e) {}
catch (UnsupportedLookAndFeelException e) {}
//Create the frame
frame1 = new JFrame ("Loan Amortization Table");
frame1.setSize (800,600);
pane = frame1.getContentPane();
insets = pane.getInsets();
pane.setLayout (null);
loan.createControls();
//Add all components to panel
pane.add (btnCalculate);
pane.add (lblPrincipal);
pane.add (lblAnnualInterestRate);
pane.add (lblMonthlyPayment);
pane.add (lblNumMonthlyPay);
pane.add (lblTotalInterestPaid);
pane.add (txtPrincipal);
pane.add (txtAnnualInterestRate);
pane.add (txtMonthlyPayment);
pane.add (txtNumMonthlyPay);
pane.add (txtTotalInterestPaid);
//Place all the components such as the Labels, buttons, and text fields.
lblPrincipal.setBounds (insets.left+5, insets.top+15, lblPrincipal.getPreferredSize().width, lblPrincipal.getPreferredSize().height);
txtPrincipal.setBounds (insets.left+5, lblPrincipal.getY() + lblPrincipal.getHeight()+5, txtPrincipal.getPreferredSize().width, txtPrincipal.getPreferredSize().height);
lblMonthlyPayment.setBounds(insets.left + 5, txtPrincipal.getY() + txtPrincipal.getHeight()+10,lblMonthlyPayment.getPreferredSize().width,lblMonthlyPayment.getPreferredSize().height);
txtMonthlyPayment.setBounds(insets.left+5,lblMonthlyPayment.getY()+lblMonthlyPayment.getHeight()+5,txtMonthlyPayment.getPreferredSize().width,txtMonthlyPayment.getPreferredSize().height);
lblAnnualInterestRate.setBounds(insets.left+5,txtMonthlyPayment.getY()+txtMonthlyPayment.getHeight()+10,lblAnnualInterestRate.getPreferredSize().width,lblAnnualInterestRate.getPreferredSize().height);
txtAnnualInterestRate.setBounds(insets.left+5,lblAnnualInterestRate.getY()+lblAnnualInterestRate.getHeight()+5,txtAnnualInterestRate.getPreferredSize().width,txtAnnualInterestRate.getPreferredSize().height);
lblNumMonthlyPay.setBounds(insets.left+ 200,insets.top+15, lblNumMonthlyPay.getPreferredSize().width, lblNumMonthlyPay.getPreferredSize().height);
txtNumMonthlyPay.setBounds(insets.left+ 200, lblNumMonthlyPay.getY()+ lblNumMonthlyPay.getHeight()+5, txtNumMonthlyPay.getPreferredSize().width, txtNumMonthlyPay.getPreferredSize().height);
lblTotalInterestPaid.setBounds(insets.left+200,txtNumMonthlyPay.getY()+txtNumMonthlyPay.getHeight()+10, lblTotalInterestPaid.getPreferredSize().width,lblTotalInterestPaid.getPreferredSize().height);
txtTotalInterestPaid.setBounds(insets.left+200,lblTotalInterestPaid.getY()+lblTotalInterestPaid.getHeight()+5,txtTotalInterestPaid.getPreferredSize().width,txtTotalInterestPaid.getPreferredSize().height);
btnCalculate.setBounds(insets.left+100,insets.top+200,btnCalculate.getPreferredSize().width, btnCalculate.getPreferredSize().height);
//Set frame visible
frame1.setVisible (true);
//Button's action
btnCalculate.addActionListener(new btnCalculateAction()); //Register action
}
public static class btnCalculateAction implements ActionListener{
public void actionPerformed (ActionEvent e){
}
}
}
The user inputs the numbers then when they press Calculate, the number of monthly payments and Total Interest Paid would show up in the text field. I can't really see how to do that part though. How would I make certain info appear in the text fields. Isn't what appears when you add the text fields determined in this section right here?
CODE
//Create controls
btnCalculate = new JButton ("Calculate");
lblPrincipal = new JLabel ("Principal");
lblAnnualInterestRate = new JLabel ("Annual Interest Rate");
lblMonthlyPayment = new JLabel ("Monthly Payment");
lblNumMonthlyPay = new JLabel ("Number of Monthly Payments");
lblTotalInterestPaid = new JLabel ("Total Interest Paid");
txtPrincipal = new JTextField (10);
txtAnnualInterestRate = new JTextField ( 10);
txtMonthlyPayment = new JTextField (10);
txtNumMonthlyPay = new JTextField(10); //I want there to be an output here.
txtTotalInterestPaid = new JTextField(10);//I want there to be an output here.
I'm sure I could make this assignment a lot easier on myself by just asking the user for the information using just Scanner class, but I guess I just want to see if this works. So ya, I would just like to know what to do in order to create an output in a textfield after the pane is already up.
Nvm, got some help from someone. This part here works
CODE
public static class btnCalculateAction implements ActionListener{
public void actionPerformed (ActionEvent e){
txtNumMonthlyPay.setText("...");
}
}
I would need to then store these inputs of the user and the outputs from the Calculate button for use in the
The program should allow multiple runs (up to 4 different versions) of the table process and should allow the user to compare runs in a tabular format part of the assignment. Which I'm guessing I can do through arrays and some type of loop. I'll figure that out later though. Use JOptionPane?
This post has been edited by emblem: 24 Aug, 2008 - 12:45 PM