Essays24.com - Term Papers and Free Essays
Search

Pos 407 Week 3

Essay by   •  November 9, 2010  •  2,783 Words (12 Pages)  •  1,315 Views

Essay Preview: Pos 407 Week 3

Report this essay
Page 1 of 12

/*

Program: Mortgage Calculator with Graphical User Interface

Current Version: 2.0

Programs accepts user input in 3 text fields: Term, Amount, and Rate.

When any field changes, Monthly Payment (output) updates.

Used Formatted Text Fields to prevent character input.

2.0 01/11/2007

Program accepts user input for the mortgage amount. Payment amount

is calculated from a radio button selection of the following:

7 year loan at 5.35%

15 year loan at 5.50%

30 year loan at 5.75%

User can also select to see an amortization table for each of the

loan choices (stored in an array)

*/

import java.awt.*; //Abstract Windows Toolkit

import java.awt.event.*; //Action Listener

import javax.swing.*;//Swing Container

import javax.swing.JScrollPane;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTable;

import java.beans.PropertyChangeListener; //allows the program to listen to property changes from any bound properties on the source bean

import java.beans.PropertyChangeEvent;

import java.text.*;//Provides classes and interfaces for handling text, dates, numbers, and messages in a manner independent of natural languages

import java.text.DecimalFormat;

import javax.swing.JMenu;

import javax.swing.JMenuItem;

import javax.swing.JMenuBar; //imports for the menu system

import javax.swing.KeyStroke;

public class MortgageGUI extends JPanel implements PropertyChangeListener, ActionListener

{ //Variable declaration here so they are accessible to all methods

//declare fields for user input and program output

private static JFrame frame = new JFrame("Monthly Mortgage Calculator");

private JFrame tableFrame = new JFrame("Amortization Table");

private JTable table; //used to hold the amortization table

private JFormattedTextField loanAmountField;

private JFormattedTextField paymentAmountField;

//set to default values for before user input has occurred

private static double interestRate; //value changed for v2.0

private static double loanAmount;

private static int term;//value changed for v2.0

//declare a JLabel for 4 objects in the program

private JLabel loanAmountLabel;

private JLabel paymentAmountLabel;

private JLabel selectionLabel;

//declare a button used for displaying the amortization table

private static JButton tableButton;

//Formats for each field for proper output

private NumberFormat loanAmountFormat;

private NumberFormat paymentAmountFormat;

private static JMenuBar mortgageMenuBar;

private static JMenu frameMenu;

private static JMenuItem helpItem, aboutItem;

//selections for the loan types

private static String [] loanChoicesStr = {"7 years at 5.35%","15 years at 5.5%","30 years at 5.75%"};

private static JComboBox loanChoicesBox = new JComboBox(loanChoicesStr);

private static JScrollPane scrollPane;

private static JComponent tablePane;

//begin methods

public MortgageGUI() //contrustor for the class

{

super(new BorderLayout(5,2)); //calls the superclass constructor and uses a layout with horizontal spacing of 4 and vertical spacing of 2

//setup menu

mortgageMenuBar = new JMenuBar();

//Build the menu.

frameMenu = new JMenu("Help");

frameMenu.setMnemonic(KeyEvent.VK_H);

frameMenu.getAccessibleContext().setAccessibleDescription("Mortgage GUI help menu");

mortgageMenuBar.add(frameMenu);

helpItem = new JMenuItem("Instructions", KeyEvent.VK_I);

helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, ActionEvent.ALT_MASK));

helpItem.getAccessibleContext().setAccessibleDescription("Displays instructions for using the Mortgage Calculator");

helpItem.addActionListener(this);

frameMenu.add(helpItem);

aboutItem = new JMenuItem("About", KeyEvent.VK_A);

...

...

Download as:   txt (12.5 Kb)   pdf (129.3 Kb)   docx (13.8 Kb)  
Continue for 11 more pages »
Only available on Essays24.com