Update: I have this working but the calculations are wrong. Where is my
mistake?
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Cbweek1b {
double a, t, i, payments;
JLabel amountLbl, termLbl, IntrateLbl, paymentsLbl;
JTextField amountTf, termTf, intrateTf, paymentsTf;
JButton calcBtn;
JFrame frame;
Font font;
public Cbweek1b() {
System.out.println("Starting Mortgage Calculator GUI.");
font = new Font("Arial",Font.BOLD,24);
amountLbl = new JLabel("Loan Amount");
termLbl = new JLabel("Terms");
IntrateLbl = new JLabel("Interest Rate");
paymentsLbl = new JLabel("Monthly amount");
amountTf = new JTextField();
termTf = new JTextField();
intrateTf = new JTextField();
paymentsTf = new JTextField();
calcBtn = new JButton("Calculate");
amountLbl.setFont(font);
termLbl.setFont(font);
IntrateLbl.setFont(font);
paymentsLbl.setFont(font);
amountTf.setFont(font);
termTf.setFont(font);
intrateTf.setFont(font);
paymentsTf.setFont(font);
calcBtn.setFont(font);
frame = new JFrame("Mortgage Calculator");
frame.setLayout(new GridLayout(6,6));
frame.add(amountLbl);
frame.add(amountTf);
frame.add(termLbl);
frame.add(termTf);
frame.add(IntrateLbl);
frame.add(intrateTf);
frame.add(paymentsLbl);
frame.add(paymentsTf);
frame.add(calcBtn);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
calcBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
calculate();
}
});
frame.setLocation(300, 200);
// frame.setSize(300, 300);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new Cbweek1b();
}
private void calculate() {
double a = Double.parseDouble(amountTf.getText());
double t = Double.parseDouble(termTf.getText());
double i = Double.parseDouble(intrateTf.getText());
double payments = a * i/ (1.0 - Math.pow(i+1,-t));
paymentsTf.setText("" + payments);
}
}
--
The best live web video on the internet
http://www.seedsv.com/webdemo.htm
NEW Embedded system W/Linux. We now sell DVR cards.
See it all at
http://www.seedsv.com/products.htm
Sharpvision simply the best
http://www.seedsv.com
"pcbutts1" <pcbutts1@seedsv.comwrote in message
news:4dudnZoWAPpYkjrZnZ2dnUVZ_sOdnZ2d@giganews.com ...
Quote:
This is a simple mortgage calculator and it compiles but I am totally
confused on the calculation to get it to work. Can someone help me a
little.
>
>
>
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
>
public class Cbweek1b {
>
double a, t, i, payments;
JLabel amountLbl, termLbl, IntrateLbl, paymentsLbl;
JTextField amountTf, termTf, intrateTf, paymentsTf;
JButton calcBtn;
JFrame frame;
Font font;
>
public Cbweek1b() {
System.out.println("Starting Mortgage Calculator GUI.");
>
font = new Font("Arial",Font.BOLD,24);
>
amountLbl = new JLabel("Loan Amount");
termLbl = new JLabel("Terms");
IntrateLbl = new JLabel("Interest Rate");
paymentsLbl = new JLabel("Monthly amount");
>
>
amountTf = new JTextField();
termTf = new JTextField();
intrateTf = new JTextField();
paymentsTf = new JTextField();
>
calcBtn = new JButton("Calculate");
>
amountLbl.setFont(font);
termLbl.setFont(font);
IntrateLbl.setFont(font);
paymentsLbl.setFont(font);
amountTf.setFont(font);
termTf.setFont(font);
intrateTf.setFont(font);
paymentsTf.setFont(font);
calcBtn.setFont(font);
>
frame = new JFrame("Mortgage Calculator");
frame.setLayout(new GridLayout(6,6));
frame.add(amountLbl);
frame.add(amountTf);
frame.add(termLbl);
frame.add(termTf);
frame.add(IntrateLbl);
frame.add(intrateTf);
frame.add(paymentsLbl);
frame.add(paymentsTf);
frame.add(calcBtn);
>
>
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
>
calcBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
calculate();
}
});
>
frame.setLocation(300, 200);
// frame.setSize(300, 300);
frame.pack();
frame.setVisible(true);
>
}
>
public static void main(String[] args) {
new Cbweek1b();
}
>
private void calculate() {
double a = Double.parseDouble(amountTf.getText());
double t = Double.parseDouble(termTf.getText());
double i = Double.parseDouble(intrateTf.getText());
double payments = a * t;
paymentsTf.setText("" + payments);
}
}
>
--
>
>
The best live web video on the internet
http://www.seedsv.com/webdemo.htm
NEW Embedded system W/Linux. We now sell DVR cards.
See it all at
http://www.seedsv.com/products.htm
Sharpvision simply the best
http://www.seedsv.com
>
>
>
>