# Gui Mortgage Calculator

Topics: Mortgage calculator, Calculation Pages: 7 (864 words) Published: September 18, 2005
GUI Mortgage Calculator
University of Phoenix
David Silberberg
POS 407
04-19-2005

Program

/*
* MortgageGui.java
* Version 4
* Created on April 19, 2005
* Use a graphical interface to allow a user to input a principle amount, interest rate * and term of loan then calculate loan payment.
* Added text field to show amortization of loan. Also checked for last payment equal to * less than monthly payment. Added in the ability to select a predefined interest rate * and term. Added in the ability to read in from a file (file is found in C:\mortgagein.txt). *

*
* @author ************
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.io.*;

public class MortgageGUI extends JFrame implements ActionListener { double total = 0; //monthly payment initalization of variables double i = 0; //interest
double p = 0; //principle
int t = 0; //term in years
int m = 0; //monthly term
double j = 0; //daily interest rate
double mPayment = 0;
double monthlyInterest = 0;
double principleOnly = 0;
double newBalance = 0;
int choice = 0;

//setup row
JPanel row = new JPanel();
JLabel heading = new JLabel("Mortgage Calculator", JLabel.CENTER); //setup row 1
JPanel row1 = new JPanel();
JLabel principle = new JLabel("Amount to Borrow:", JLabel.RIGHT); JTextField princ = new JTextField("100000", 6);
JLabel term = new JLabel(" Years:", JLabel.RIGHT);
JTextField years = new JTextField("", 3);
JLabel rate = new JLabel(" Interest Rate:", JLabel.RIGHT); JTextField irate = new JTextField("", 4);
//setup row 2
JPanel row2 = new JPanel();
JLabel termInt = new JLabel("Select the Term and interest rate:", JLabel.LEFT); String[] formats = {"Choose from below or enter your own","7 years @ 5.35%", "15 years @ 5.5%", "30 years @ 5.75%","Enter a file in line below"}; JComboBox combo = new JComboBox();

//setup row 3
JPanel row3 = new JPanel();
JLabel fileText = new JLabel("Enter file name and location to read from:", JLabel.RIGHT); JTextField textFile = new JTextField("", 12);
//setup row 4
JPanel row4 = new JPanel();
JLabel monthlyPayment = new JLabel("Monthly Payment:", JLabel.RIGHT); JTextField mthPay = new JTextField(9);
//setup row 5
JPanel row5 = new JPanel();
JButton Calculate = new JButton("Calculate");
JButton Reset = new JButton("Reset");
JButton Quit = new JButton("Quit");
//setup row 6
JPanel row6 = new JPanel();
JTextArea mortg = new JTextArea(5, 40);
JLabel header = new JLabel("Payment# Principle Balance Interest \n",JLabel.LEFT); JScrollPane scroll = new JScrollPane(mortg, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

public MortgageGUI() { //creating layout for the GUI
super("Mortgage Calculator");
setSize (500, 720);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
Container pane = getContentPane();
GridLayout layout = new GridLayout(7, 1, 1, 1);
pane.setLayout(layout);
setVisible(true);
FlowLayout layout0 = new FlowLayout(FlowLayout.CENTER, 2, 2); row.setLayout(layout0);
FlowLayout layout1 = new FlowLayout(FlowLayout.LEFT, 2, 2); row1.setLayout(layout1);
FlowLayout layout2 = new FlowLayout(FlowLayout.LEFT, 2, 2); row2.setLayout(layout2);