Essays24.com - Term Papers and Free Essays
Search

Mortgagecalc.Java

Essay by   •  November 3, 2010  •  604 Words (3 Pages)  •  971 Views

Essay Preview: Mortgagecalc.Java

Report this essay
Page 1 of 3

//Import statements

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.text.DecimalFormat;

import javax.swing.JOptionPane;

//class header

//Frame=top-level container | the MortgageCalc class will be a subclass of "Frame"

//ActionListener tells program to listen for/respond to user event

public class MortgageCalc extends Frame implements ActionListener

{

//declare variables

private Button calculateBTN;

private Button quitBTN;

private TextField amountTXF;

private TextField termTXF;

private TextField rateTXF;

private DecimalFormat calcPattern;

private boolean hitCalculate;

private Panel calcPNL;

private Panel textFieldsPNL;

private Label amountLBL;

private Label rateLBL;

private Label termLBL;

//constructor method header

public MortgageCalc()

{

//creates menu bar

MenuBar mnuBar = new MenuBar();

setMenuBar(mnuBar);

//adds "File" to menu bar

Menu mnuFile = new Menu("File", true);

mnuBar.add(mnuFile);

MenuItem mnuFileExit = new MenuItem("Exit");

mnuFile.add(mnuFileExit);

//adds "About" to menu bar

Menu mnuAbout = new Menu("About", true);

mnuBar.add(mnuAbout);

MenuItem mnuAboutMortgageCalculator = new MenuItem("About Mortgage Calculator");

mnuAbout.add(mnuAboutMortgageCalculator);

//add ActionListener to menu items

mnuFileExit.addActionListener(this);

mnuAboutMortgageCalculator.addActionListener(this);

//sets ActionCommand to menu items

mnuFileExit.setActionCommand("Exit");

mnuAboutMortgageCalculator.setActionCommand("About");

//initialize variables...

//set text field, size 10 char, editable

amountTXF = new TextField(10);

amount.setEditable(true);

//set text field, size 10 char, editable

termTXF = new TextField(10);

term.setEditable(true);

//set text field, size 10 char, editable

rateTXF = new TextField(10);

rate.setEditable(true);

//set panels

calcPNL = new Panel();

textFieldsPNL = new Panel();

calcPNL.setLayout(new GridLayout(4, 6));

//layout of panels

textFieldsPNL.setLayout(new GridLayout(4, 6));

textFieldsPNL.add(amountLBL);

textFieldsPNL.add(amountTXF);

textFieldsPNL.add(rateLBL);

textFieldsPNL.add(rateTXF);

textFieldsPNL.add(termLBL);

textFieldsPNL.add(termTXF);

//calculate button

calculateBTN = new Button ("Calculate");

calculateBTN.addActionListener(this);

//set decimal format

calcPattern = new DecimalFormat("#########.##");

//initialize boolean "true" for hitting the calculate button

hitCalculate = true;

...

...

Download as:   txt (4.2 Kb)   pdf (79.3 Kb)   docx (10.3 Kb)  
Continue for 2 more pages »
Only available on Essays24.com