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.prin tln("Starting Mortgage Calculator GUI.");
font = new Font("Arial",Fo nt.BOLD,24);
amountLbl = new JLabel("Loan Amount");
termLbl = new JLabel("Terms") ;
IntrateLbl = new JLabel("Interes t Rate");
paymentsLbl = new JLabel("Monthly amount");
amountTf = new JTextField();
termTf = new JTextField();
intrateTf = new JTextField();
paymentsTf = new JTextField();
calcBtn = new JButton("Calcul ate");
amountLbl.setFo nt(font);
termLbl.setFont (font);
IntrateLbl.setF ont(font);
paymentsLbl.set Font(font);
amountTf.setFon t(font);
termTf.setFont( font);
intrateTf.setFo nt(font);
paymentsTf.setF ont(font);
calcBtn.setFont (font);
frame = new JFrame("Mortgag e Calculator");
frame.setLayout (new GridLayout(6,6) );
frame.add(amoun tLbl);
frame.add(amoun tTf);
frame.add(termL bl);
frame.add(termT f);
frame.add(Intra teLbl);
frame.add(intra teTf);
frame.add(payme ntsLbl);
frame.add(payme ntsTf);
frame.add(calcB tn);
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
calcBtn.addActi onListener(new ActionListener( ) {
public void actionPerformed (ActionEvent e) {
calculate();
}
});
frame.setLocati on(300, 200);
// frame.setSize(3 00, 300);
frame.pack();
frame.setVisibl e(true);
}
public static void main(String[] args) {
new Cbweek1b();
}
private void calculate() {
double a = Double.parseDou ble(amountTf.ge tText());
double t = Double.parseDou ble(termTf.getT ext());
double i = Double.parseDou ble(intrateTf.g etText());
double payments = a * t;
paymentsTf.setT ext("" + 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
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.prin tln("Starting Mortgage Calculator GUI.");
font = new Font("Arial",Fo nt.BOLD,24);
amountLbl = new JLabel("Loan Amount");
termLbl = new JLabel("Terms") ;
IntrateLbl = new JLabel("Interes t Rate");
paymentsLbl = new JLabel("Monthly amount");
amountTf = new JTextField();
termTf = new JTextField();
intrateTf = new JTextField();
paymentsTf = new JTextField();
calcBtn = new JButton("Calcul ate");
amountLbl.setFo nt(font);
termLbl.setFont (font);
IntrateLbl.setF ont(font);
paymentsLbl.set Font(font);
amountTf.setFon t(font);
termTf.setFont( font);
intrateTf.setFo nt(font);
paymentsTf.setF ont(font);
calcBtn.setFont (font);
frame = new JFrame("Mortgag e Calculator");
frame.setLayout (new GridLayout(6,6) );
frame.add(amoun tLbl);
frame.add(amoun tTf);
frame.add(termL bl);
frame.add(termT f);
frame.add(Intra teLbl);
frame.add(intra teTf);
frame.add(payme ntsLbl);
frame.add(payme ntsTf);
frame.add(calcB tn);
frame.setDefaul tCloseOperation (JFrame.EXIT_ON _CLOSE);
calcBtn.addActi onListener(new ActionListener( ) {
public void actionPerformed (ActionEvent e) {
calculate();
}
});
frame.setLocati on(300, 200);
// frame.setSize(3 00, 300);
frame.pack();
frame.setVisibl e(true);
}
public static void main(String[] args) {
new Cbweek1b();
}
private void calculate() {
double a = Double.parseDou ble(amountTf.ge tText());
double t = Double.parseDou ble(termTf.getT ext());
double i = Double.parseDou ble(intrateTf.g etText());
double payments = a * t;
paymentsTf.setT ext("" + 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
Comment