When I press the 7 year with 5.35% the amort table goes across the screen instead of down. When I press the 30 year with 5.75% it exit the program. I cannot figure out what I did wrong, will someone please check and help quick. Here are my codes.
Code:
//Set up and initialize buttons for GUI
bCalc7 = new JButton ("7 Year, 5.32%");
bCalc7.setActionCommand ("Calculate7");
bCalc15 = new JButton ("15 Years, 5.50%");
bCalc15.setActionCommand ("Calculate15");
bCalc30 = new JButton ("30 Years, 5.75%");
bCalc30.setActionCommand ("Calculate30");
bClear = new JButton ("Clear All Fields");
bClear.setActionCommand ("Clear");
bExit = new JButton ("Exit Program");
bExit.setActionCommand ("Exit");
//Set up labels and field sizes for GUI
labelTitle = new JLabel ("McBride Mortgage Calculator V3.5");
labelInstructions = new JLabel ("Enter the amount of the Loan and then choose the term/rate of the loan.");
labelPayment = new JLabel ("Monthly Payment:");
labelLoanAmount = new JLabel ("Amount of Loan:");
fieldPayment = new JTextField ("", 12);
fieldLoanAmount = new JTextField ("", 10);
labelAmortTable = new JLabel ("Amortization Table");
areaAmortTable = new JTextArea (10, 300);
JScrollPane scrollPane = new JScrollPane (areaAmortTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
//Set up listerners for each button
bCalc7.addActionListener (this);
bCalc15.addActionListener (this);
bCalc30.addActionListener (this);
bClear.addActionListener (this);
bExit.addActionListener (this);
//Construct GUI and set layout
JPanel calu = new JPanel();
calu.setLayout (null);
calu.add (labelTitle);
labelTitle.setBounds (110,30,700,15);
calu.add (labelInstructions);
labelInstructions.setBounds(30, 70, 450, 15);
calu.add (labelLoanAmount);
labelLoanAmount.setBounds(130, 110, 100, 25);
calu.add (fieldLoanAmount);
fieldLoanAmount.setBounds(240, 110, 100, 25);
calu.add (bCalc7);
bCalc7.setBounds(40, 150, 125, 30);
calu.add (bCalc15);
bCalc15.setBounds(180, 150, 125, 30);
calu.add (bCalc30);
bCalc30.setBounds(320, 150, 125, 30);
calu.add (labelPayment);
labelPayment.setBounds(130, 200, 100, 25);
calu.add (fieldPayment);
fieldPayment.setBounds(240, 200, 100, 25);
fieldPayment.setEditable(false);
calu.add (labelAmortTable);
labelAmortTable.setBounds(180, 250, 300, 25);
calu.add (scrollPane);
scrollPane.setBounds(50, 280, 400, 270);
areaAmortTable.setEditable(false);
calu.add (bClear);
bClear.setBounds(110, 570, 125, 30);
calu.add (bExit);
bExit.setBounds(250, 570, 125, 30);
this.setContentPane(calu);
this.pack();
this.setTitle("Mortgage Calculator5");
//Set windwo size
Dimension screenSize = Toolkit.getDefaultToolkit() .getScreenSize();
setSize (600, 700);
}
public double loanAmount ()
{
double loanAmount = Double.parseDouble (fieldLoanAmount.getText());
return loanAmount;
}
}
Comment