Not sure if I'm looking at it right. But I wrote a program that is going to display 3 different mortgages at once. But they all stream together, I'm trying to block them where each mortgage has its own area in my GUI window. Can someone point me in the right direction?
Not sure how too!!!
Collapse
X
-
Tags: None
-
Okay this is what I have. I'm trying to get my program to show 3 different mortgages neatly. An maybe throw in a menu prompt that you could chose which mortgage you would like to see first. Can anyone help me with that?
import java.awt.*;
import javax.swing.*;
import java.awt.event. *;
import java. text.*;
public class wk3_jrs extends JFrame implements ActionListener
{
JLabel amountLabel = new JLabel("Princip le Loan");
JTextField amountField = new JTextField(7);
JLabel termLabel1 = new JLabel("Term of loan");
JTextField termField1 = new JTextField(4);
JLabel interestLabel1 = new JLabel("Interes t Rate");
JTextField interestField1 = new JTextField(5);
JTextField paymentField1 = new JTextField(9);
JLabel termLabel2 = new JLabel("Term of loan");
JTextField termField2 = new JTextField(4);
JLabel interestLabel2 = new JLabel("Interes t Rate");
JTextField interestField2 = new JTextField(5);
JTextField paymentField2 = new JTextField(9);
JLabel termLabel3 = new JLabel("Term of loan");
JTextField termField3 = new JTextField(4);
JLabel interestLabel3 = new JLabel("Interes t Rate");
JTextField interestField3 = new JTextField(5);
JTextField paymentField3 = new JTextField(9);
JButton calculate = new JButton("Calcul ate Payment");
JButton myButton = new JButton("Clear" );
JButton myButton1 = new JButton("Exit") ;
public wk3_jrs()
{
super("Joe's Mortgage Calculator");
setSize(700, 400);
setDefaultClose Operation(JFram e.EXIT_ON_CLOSE );
setVisible(true );
Container pane = getContentPane( );
FlowLayout layout = new FlowLayout();
pane.add(amount Label);
pane.add(amount Field);
pane.add(termLa bel1);
pane.add(termFi eld1);
pane.add(intere stLabel1);
pane.add(intere stField1);
pane.add(paymen tField1);
System.out.prin tln ("\n");
pane.add(termLa bel2);
pane.add(termFi eld2);
pane.add(intere stLabel2);
pane.add(intere stField2);
pane.add(paymen tField2);
System.out.prin tln ("\n");
pane.add(termLa bel3);
pane.add(termFi eld3);
pane.add(intere stLabel3);
pane.add(intere stField3);
pane.add(paymen tField3);
pane.add(calcul ate);
pane.add(myButt on);
pane.add(myButt on1);
pane.add(myButt on);
pane.add(myButt on1);
pane.setLayout( layout);
setContentPane( pane);
pane.setBackgro und(Color.red);
amountField.add ActionListener( this);
termField1.addA ctionListener(t his);
interestField1. addActionListen er(this);
paymentField1.a ddActionListene r(this);
termField2.addA ctionListener(t his);
interestField2. addActionListen er(this);
paymentField2.a ddActionListene r(this);
termField3.addA ctionListener(t his);
interestField3. addActionListen er(this);
paymentField3.a ddActionListene r(this);
calculate.addAc tionListener(th is);
myButton.addAct ionListener(thi s);
myButton1.addAc tionListener(th is);
}
public void actionPerformed (ActionEvent event)
{
Object source = event.getSource ();
if(source == calculate)
{
double a = 200000;
double[] t = {30, 15, 7};
double[] i = {0.0575, 0.0550, 0.0575};
double payment1, payment2, payment3;
payment1 = (a*(i[0]/12)/(1-Math.pow(1+i[0], -t[0]*12)));
payment2 = (a*(i[1]/12)/(1-Math.pow(1+i[1], -t[1]*12)));
payment3 = (a*(i[2]/12)/(1-Math.pow(1+i[2], -t[2]*12)));
DecimalFormat decimalpoint = new DecimalFormat(" 0,000.00");
paymentField1.s etText("$ "+decimalpoint. format (payment1));
paymentField2.s etText("$ "+decimalpoint. format (payment2));
paymentField3.s etText("$ "+decimalpoint. format (payment3));
}
if(source == myButton)
{
amountField.set Text(null);
termField1.setT ext(null);
interestField1. setText(null);
paymentField1.s etText(null);
termField2.setT ext(null);
interestField2. setText(null);
paymentField2.s etText(null);
termField3.setT ext(null);
interestField3. setText(null);
paymentField3.s etText(null);
}
if(source == myButton1)
{
System.exit(0);
}
}
public static void main(String[]args)
{
wk3_jrs calc = new wk3_jrs();
}
}
Comment