Java Calculator
By: Mikki • Research Paper • 3,979 Words • March 1, 2010 • 696 Views
Join now to read essay Java Calculator
/*
Mortgage Calculator
Date: April 16, 2008
Filename: MortgageCalc.java
Purpose: This is a program to calculate the mortgage using user input.
*/
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.*;
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class MortgageCalc extends Frame implements ActionListener
{
private Button keys[];
private Panel userInterface, buttonInterface, result1Interface, result2Interface;
private TextField tfMortgagePayment, tfMortgageAmount;
private TextArea tfMonthlyPayments;
private Label label1, label2, label3, label4;
private Choice availableLoans;
private double mortgagePayment, loanBalance=0;
private boolean foundKey;
private DecimalFormat roundDecimal;
private double [] intRateAnnual = {5.35, 5.50, 5.75};
private int termMonths, arrayIndex=0;
private int [] termYears = {7, 15, 30};
//MortgageCalc constructor
public MortgageCalc() //throws IOException
{
roundDecimal = new DecimalFormat("########.##");
// create an instance of the menu
MenuBar mnuBar = new MenuBar();
setMenuBar(mnuBar);
// construct and populate the File menu
Menu mnuFile = new Menu("File", true);
mnuBar.add(mnuFile);
MenuItem mnuFileExit = new MenuItem("Exit");
mnuFile.add(mnuFileExit);
// construct and populate the Edit menu
Menu mnuEdit = new Menu("Edit", true);
mnuBar.add(mnuEdit);
MenuItem mnuEditClear = new MenuItem("Clear");
mnuEdit.add(mnuEditClear);
// construct and populate the About menu
Menu mnuAbout = new Menu("About", true);
mnuBar.add(mnuAbout);
MenuItem mnuAboutCalculator = new MenuItem("Mortgage Calculator");
mnuAbout.add(mnuAboutCalculator);
// add the ActionListener to each menu item
mnuFileExit.addActionListener(this);
mnuEditClear.addActionListener(this);
mnuAboutCalculator.addActionListener(this);
// assign an ActionCommand to each menu item
mnuFileExit.setActionCommand("Exit");
mnuEditClear.setActionCommand("Clear");
mnuAboutCalculator.setActionCommand("About");
// construct components and initialize beginning values
tfMortgageAmount = new TextField(20);
tfMortgageAmount.setEditable(true);
tfMortgagePayment = new TextField(20);
tfMortgagePayment.setEditable(false);
tfMonthlyPayments = new TextArea("",5,55);