Pos 407 Week 2
Essay by 24 • November 4, 2010 • 758 Words (4 Pages) • 1,453 Views
//Week2 Nicholas Zarnin
/*
Week 2: Mortgage Calculator
Programmer: Nicholas Zarnin
Date: June 11, 2006
Filename: Mortgage.java
Purpose: This program accepts input from a user for principal amount, term, and interest rate, and calculates the payment. This program allows users to enter new information, or exit the program
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Locale;
import java.text.*;
class Mortgage extends JFrame
implements ActionListener {
JButton Calculate;
JButton Reset;
// What the text box is.
JLabel loanLabel;
JLabel interestLabel;
JLabel yearsLabel;
JLabel paymentLabel;
//Where user Inputs Data, and results too!
JTextField loanTextbox;
JTextField interestTextbox;
JTextField yearsTextbox;
JTextField paymentTextbox;
JTextField paymentfield;
//Set the variables to 0, ready for input
double amount=0;
double years=0;
double interest=0;
double totalpayments=0;
double monthly_interest_rate=0;
double monthly_payment=0;
double totalcalc=0;
//Currency Information for regional formatting
NumberFormat curr = NumberFormat.getCurrencyInstance(Locale.US);
// This is where the form all comes together
public Mortgage (int width, int height)
{
this.setTitle ("Nick's Mortgage Calculator");
this.setResizable (true);
this.setSize (400, 400);
this.setLocationRelativeTo(null);
//This is how its going to close
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cPane = this.getContentPane();
cPane.setLayout (new GridLayout(0,2));
//The Calculate and reset botton
Calculate = new JButton ("Calculate");
Calculate.addActionListener (this);
cPane.add (Calculate);
Reset = new JButton("Reset");
Reset.addActionListener (this);
cPane.add (Reset);
//This is where I declare the Fields and the Labels for the GUI
loanLabel = new JLabel ("Loan Amount");
cPane.add (loanLabel);
loanTextbox = new JTextField ();
cPane.add (loanTextbox);
interestLabel = new JLabel ("Interest Rate");
cPane.add (interestLabel);
interestTextbox = new JTextField ();
cPane.add (interestTextbox);
yearsLabel = new JLabel ("# of Years");
cPane.add (yearsLabel);
yearsTextbox = new JTextField ();
cPane.add (yearsTextbox);
paymentLabel = new JLabel ("Monthly Payment");
cPane.add (paymentLabel);
paymentfield = new JTextField ();
cPane.add (paymentfield);
// Display the Java GUi
this.setVisible (true);
}
// This is where the process starts of taking information
public void actionPerformed (ActionEvent a)
...
...