# Assistance with GUI Mortgage Calculator

Page 1 of 1

## 2 Replies - 3640 Views - Last Post: 20 November 2007 - 01:26 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=37487&amp;s=e68207d20364d8bb6defc5839ab006d8&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 A_town_clown

Reputation: 0
• Posts: 3
• Joined: 11-November 07

# Assistance with GUI Mortgage Calculator

Posted 15 November 2007 - 12:05 AM

Hello people, I am here to enlist the help of those with a greater knowledge of programming than myself. I am a newbie to the programming scene and this is my first program. While I have somewhat of a grasp on simple things, can some one please assit me...My first problem is that I can not get the calculations correct. I've tried several formula's but thy all come out the same way, something like this: 4655.690405738445. Also, I have the slightest clue as to how to list the loan balance and interest paid for each payment over the term of the loan.

Charles

``` /*
* Morgage Application.  Calcualte the payments based on the amounts, terms and
* interest rates.  Show a list of the balance and the interest paid.
* Title	 WK 3 Calculator
* author	Charles I. Clay
* Date	  11/10/07
* version   1.0
*/

//Imports
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//Create GUI fields, labels, and buttons
public class WK3Calculator extends JFrame implements ActionListener {
private JLabel labela;
private JLabel labelt;
private JLabel labelr;
private JTextField textFieldAmount;
private JTextField textFieldTerm;
private JTextField textFieldRate;
private JTextField textFieldResult;
private JButton buttonCalc;

public WK3Calculator() {
initComponents();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
pack();

}

public void initComponents() {
//Initialization of Components
labela = new JLabel("Amount of Loan");
textFieldAmount = new JTextField();
labelt = new JLabel("Term of Loan");
textFieldTerm = new JTextField();
labelr = new JLabel("Interest Rate");
textFieldRate = new JTextField();
textFieldResult = new JTextField();
buttonCalc = new JButton("Calculate");

//Set Attributes
textFieldResult.setEditable(false);
textFieldResult.setColumns(8);
textFieldAmount.setColumns(6);
textFieldTerm.setColumns(2);
textFieldRate.setColumns(2);

Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());

//Addition of components to the panel

}

public static void main(String[] args) {
WK3Calculator frame = new WK3Calculator();
}

private void setResultValue() {
double amount = Double.parseDouble (textFieldAmount.getText());
double term = Integer.parseInt(textFieldTerm.getText());
double rate = Double.parseDouble(textFieldRate.getText()) / 100.;
double result = amount * ( rate * Math.pow ( ( 1 + rate ), term ) ) / ( Math.pow( ( 1 + rate ), term ) - 1 );

textFieldResult.setText(Double.toString(result));
}

public void actionPerformed(ActionEvent event) {
System.out.println("Action Button");
String command = event.getActionCommand();
if (command == "Calculate") {
setResultValue();
}
}
}

```

Is This A Good Question/Topic? 0

## Replies To: Assistance with GUI Mortgage Calculator

### #2 Martyr2

• Programming Theoretician

Reputation: 5187
• Posts: 13,917
• Joined: 18-April 07

## Re: Assistance with GUI Mortgage Calculator

Posted 16 November 2007 - 04:10 PM

For the formula and even an example of using this project with a GUI you can check out my advice on the following thread...

Mortgage Calculator With GUI

There I show superczech how to fix his problems with the calculation. The project he created is one of the nicer ones so if you want to make an example with it, just copy and paste and run it. Then you will be able to tinker with it and see how the calculation works across multiple time spans with multiple interest rates.

### #3 A_town_clown

Reputation: 0
• Posts: 3
• Joined: 11-November 07

## Re: Assistance with GUI Mortgage Calculator

Posted 20 November 2007 - 01:26 AM

Martyr2,
I know this may be along shot, but I've run into bigger problems and would like some assistance if you have time. I had to give up on fixing the calculations because my assignment was due. I would greatly appreciate some assistance with figuring out this piece of the pie. I had to create a manual/automatic GUI calculator, and unfortunately, when I press one of the fixed calculations buttons, it disappears on me....I am beyond lost...PLEASE HELP!