August 28, 2010, 1:46 pm
/*
Week 4: Individual Assignment PRG 421
Programmer: Robert Hazekamp
Change Request #6 Service Request SR-mf-003
Purpose: Write the program in Java (with a graphical user interface) so that it will
allow the user to select which way they want to calculate a mortgage: by input of
the amount of the mortgage, the term of the mortgage, and the interest rate of the
mortgage payment or by input of the amount of a mortgage and then select from
a menu of mortgage loans:
- 7 year at 5.35%
- 15 year at 5.5 %
- 30 year at 5.75%
In either case, display the mortgage payment amount and then, list the loan
balance and interest paid for each payment over the term of the loan. Allow the
user to loop back and enter a new amount and make a new selection, or quit.
Insert comments in the program to document the program.
*/
//opening libraries
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import javax.swing.JOptionPane;
//declaring content
public class mortgageguiwk4 extends JFrame implements ActionListener
{
public static void main(String[] args) {
// TODO code application logic here
}
//adding initial selection options via RadioButtons
JPanel row_aa = new JPanel();
JRadioButton opt1 = new JRadioButton("Manual Input", true);
JRadioButton opt2 = new JRadioButton("Menu Selections", false);
//content Buttons, Panels, Labels, and TextFields
JPanel row_a = new JPanel();
JLabel amntLabel = new JLabel();
JTextField loanField = new JTextField();
JLabel loan2Label = new JLabel();
JPanel row_b = new JPanel();
JPanel row_b1 = new JPanel();
JLabel termLabel = new JLabel(); //term
JTextField termField = new JTextField(4);
JPanel row_b2 = new JPanel();
JLabel int_entryLabel = new JLabel(); //interest
JTextField int_entryField = new JTextField(3);
JComboBox options = new JComboBox();
JLabel optionsLabel = new JLabel();
JPanel row_c = new JPanel();
JButton calButton = new JButton();
JButton resetButton = new JButton();
JButton endButton = new JButton();
JPanel row_d = new JPanel();
JLabel paymtLabel = new JLabel();
JTextField paymtField = new JTextField();
JPanel row_e = new JPanel();
JLabel outputLabel = new JLabel();
JPanel row_f = new JPanel();
JTextArea opField = new JTextArea(5, 55);
JScrollPane scrollPane = new JScrollPane(opField,
ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
ButtonGroup radioSelect = new ButtonGroup();
private String i;
//setting format of GUI layout
public mortgageguiwk4()
{
//main GUI Dimensions super("mortgateguiWeek 4- Loan Calculator with Preselected or Customized Values");
setSize(900, 265);
new GridLayout(6, 4, 10, 10);
FlowLayout flowCenter = new FlowLayout(FlowLayout.CENTER);
FlowLayout flow = new FlowLayout(FlowLayout.LEFT);
Container pane = getContentPane();
pane.setLayout(flow);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
//setting actionListeners for Fields and Buttons
loanField.addActionListener(this);
termField.addActionListener(this);
int_entryField.addActionListener(this);
options.addActionListener(this);
calButton.addActionListener(this);
resetButton.addActionListener(this);
endButton.addActionListener(this);
opt1.addActionListener(this);
opt2.addActionListener(this);
//layout for mortgage amount entry
row_a.setLayout(flow);
amntLabel.setText("Please Enter Loan Amount w/o Commas:");
row_a.add(amntLabel);
row_a.add(loanField);
radioSelect.add(opt1);
radioSelect.add(opt2);
pane.add(row_a);
//layout for options
options.addItem("7 years at 5.35%");
options.addItem("15 years at 5.5%");
options.addItem("30 years at 5.75%");
options.setEnabled(false);
row_b.setLayout(flow);
row_b.add(options);
pane.add(row_b);
row_b1.setLayout(flow);
termLabel.setText("Term in Years");
row_b1.add(termLabel);
row_b1.add(termField);
pane.add(row_b1);
row_b2.setLayout(flow);
int_entryLabel.setText("Interest %");
row_b2.add(int_entryLabel);
row_b2.add(int_entryField);
pane.add(row_b2);