/****************************************************************/
/* MortgageCalc2 */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MortgageCalc2 extends JFrame
{
private double interest = 5.75;
private double length = 30;
private JLabel jLabel1;
private JRadioButton ibutton1;
private JRadioButton ibutton2;
private JRadioButton ibutton3;
private JTextField field_amount;
private JTextField field_paymentamount;
private JTextField field_paymentdisplay;
private JButton button_calculate;
private JButton button_clear;
private JPanel contentPane;
private ButtonGroup interestselect;
public MortgageCalc2()
{
super();
initializeComponent();
this.setVisible(true);
}
private void initializeComponent()
{
jLabel1 = new JLabel();
ibutton1 = new JRadioButton();
ibutton2 = new JRadioButton();
ibutton3 = new JRadioButton();
field_amount = new JTextField();
field_paymentamount = new JTextField();
JTextArea field_paymentdisplay = new JTextArea();
button_calculate = new JButton();
button_clear = new JButton();
contentPane = (JPanel)this.getContentPane();
interestselect = new ButtonGroup();
jLabel1.setText("Mortgage Amount:");
ibutton1.setText("5 Year at 5.35% interest");
ibutton1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e)
{
interest = 5.35;
length = 7;
}
});
ibutton2.setText("15 Year at 5.5% interest");
ibutton2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e)
{
interest = 5.5;
length = 15;
}
});
ibutton3.setText("30 Year at 5.75% Interest");
ibutton3.setSelected(true);
ibutton3.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e)
{
interest = 5.75;
length = 30;
}
});
field_amount.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
field_amount_actionPerformed(e);
}
});
field_paymentamount.setText("-Monthly Payment Amount-");
field_paymentamount.setEditable(false);
field_paymentamount.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
field_paymentamount_actionPerformed(e);
}
});
field_paymentdisplay.setText(" ");
button_calculate.setText("Calculate");
button_calculate.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
button_calculate_actionPerformed(e);
}
});
button_clear.setText("Clear");
button_clear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
button_clear_actionPerformed(e);
}
});
contentPane.setLayout(null);
addComponent(contentPane, jLabel1, 13,10,95,18);
addComponent(contentPane, ibutton1, 14,69,143,24);
addComponent(contentPane, ibutton2, 14,92,143,24);
addComponent(contentPane, ibutton3, 13,114,149,24);
addComponent(contentPane, field_amount, 12,31,100,22);
addComponent(contentPane, field_paymentamount, 15,154,134,22);
addComponent(contentPane, field_paymentdisplay, 175,21,190,184);
addComponent(contentPane, button_calculate, 14,223,83,28);
addComponent(contentPane, button_clear, 103,223,83,28);
interestselect.add(ibutton2);
interestselect.add(ibutton1);
interestselect.add(ibutton3);
this.setTitle("MortgageCalc2 - extends JFrame");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(390, 300));
}
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
private void button_calculate_actionPerformed(ActionEvent e)
{
System.out.println("\nbutton_calculate_actionPerformed(ActionEvent e) called.");
String amount1 = field_amount.getText();
Float amount = new Float(amount1);
double j = ( interest / ( 12 * 100 ) ) ;
double n = ( length * 12 );
double payment = ( amount * ( j / ( 1 - Math.pow( ( 1 + j ), -n ))));
String payment2 = Double.toString(payment);
field_paymentamount.setText(payment2);
double paymentadd = 0;
double paymentcount = 0;
while (paymentadd<amount) {
paymentadd = paymentadd + payment;
paymentcount = paymentcount + 1;
String doublepaymentadd1 = Double.toString(paymentadd);
String doublepaymentcount1 = Double.toString(paymentcount);
JTextArea.insert(doublepaymentadd1, doublepaymentcount1);
}
}
private void button_clear_actionPerformed(ActionEvent e)
{
System.out.println("\nbutton_clear_actionPerformed(ActionEvent e) called.");
}
}