Nigel,
I made your suggested changes and the code compiles now. Thanks
However when I press the calculate button I still do not get anything to print to the text area. The entire code now looks like this:
import javax.swing.*; //importing the ability to create and use a frame
import java.awt.*; //importing the swing functions like the combo box
import java.awt.event.*;
import java.lang.String;
public class MortgageFrame4 extends JFrame implements ItemListener, ActionListener, Runnable{
//setting up my variables
String paythis;
double monthly;
int a;
int t;
double I;
double total;
int loop;
double balance;
String actInt;
//creating lables, boxes, arrays, and buttons
JLabel amountLabel = new JLabel ("House cost in dollars:");
JComboBox amount = new JComboBox();{
amount.addItem("$100,000");
amount.addItem("$125,000");
amount.addItem("$150,000");
amount.addItem("$175,000");
amount.addItem("$200,000");
amount.addItem("$225,000");
amount.addItem("$250,000");
amount.addItem("$275,000");
}
JLabel tILabel = new JLabel ("Payment term and rate:");
String[] termsInterestArray = {"7 years at 5.35%", "15 years at 5.5%", "30 years at 5.75%"};
String[] termsArray = {"7 years", "15 years", "30 years"};
String[] interestArray = {"5.35%", "5.5%", "5.75%"};
JComboBox tI = new JComboBox(termsInterestArray);
JComboBox term = new JComboBox(termsArray);
JComboBox interest = new JComboBox(interestArray);
JButton calculate = new JButton("Calculate");
JButton quit = new JButton("Quit");
JLabel heading = new JLabel (" Payment # | Loan Balance | Interest Paid");
JTextArea future = new JTextArea (45, 365);
JScrollPane futureInfo = new JScrollPane(future);
JCheckBox seperateCheck = new JCheckBox("Check to select term and interest seperately");
JCheckBox tICheck = new JCheckBox("Check to select term and interest together");
ButtonGroup select = new ButtonGroup();
public MortgageFrame4(){
//setting up the frame and frame characteristics
setTitle("Mortgage calculator");
setSize(340,350);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true); //user can see the box
FlowLayout flo = new FlowLayout();
Container pane = getContentPane();
future.setLineWrap(true);
select.add(seperateCheck);
select.add(tICheck);
//setting the default layout manager and adding everything to the container
pane.setLayout(flo);
pane.add(amountLabel);
pane.add(amount);
pane.add(tILabel);
pane.add(tICheck);
pane.add(tI);
pane.add(seperateCheck);
pane.add(term);
pane.add(interest);
pane.add(calculate);
pane.add(quit);
pane.add(heading);
pane.add(futureInfo);
setContentPane(pane);
//setting up the listeners
amount.addItemListener(this);
tI.addItemListener(this);
term.addItemListener(this);
interest.addItemListener(this);
seperateCheck.addItemListener(this);
tICheck.addItemListener(this);
calculate.addActionListener(this);
quit.addActionListener(this);
repaint();
}
//this is where the program will act upon the user selections
public void itemStateChanged(java.awt.event.ItemEvent e){
}
//This is where the calculate button functionality comes from
public void actionPerformed(ActionEvent event){
if(event.getSource() == calculate){
String strA = (String)amount.getSelectedItem();
if (strA.equals("$100,000")){
a = 100000;
}
else if (strA.equals("$125,000")){
a = 125000;
}
else if (strA.equals("$150,000")){
a = 150000;
}
else if (strA.equals("$175,000")){
a = 175000;
}
else if (strA.equals("$200,000")){
a = 200000;
}
else if (strA.equals("$225,000")){
a = 225000;
}
else if (strA.equals("$250,000")){
a = 250000;
}
else if (strA.equals("$275,000")){
a = 275000;
}
if (seperateCheck.isSelected()){
String strT = (String)term.getSelectedItem();
if (strT.equals("7 years")){
t = 7*12;
}
else if (strT.equals("15 years")){
t = 15*12;
}
else if (strT.equals("30 years")){
t = 30*12;
}
String strI = (String)interest.getSelectedItem();
if (strI.equals("5.35%")){
I = 0.0535;
}
else if (strI.equals("5.5%")){
I = 0.055;
}
else if (strI.equals("5.75%")){
I = 0.0575;
}
}
else if (tICheck.isSelected()){
String strT = (String)tI.getSelectedItem();
if (strT.equals("7 years at 5.35%")){
t = 7*12;
I = 0.0535;
}
else if (strT.equals("15 years at 5.5%")){
t = 15*12;
I = 0.055;
}
else if (strT.equals("30 years at 5.75%")){
t = 30*12;
I = 0.0575;
}
}
total = (a*t*I);
balance = (total - (monthly*loop));
actInt = ("$" + (monthly * I));
}
else if(event.getSource() == quit){
System.exit(0);
}
}
public void run(){
while (balance >= 0){
for (int loop = 1; loop <= t; loop ++){
future.setText(loop + balance + actInt);
repaint();
}
}
}
//this is the main function where the program runs
public static void main(String[] arguments){
MortgageFrame4 mor = new MortgageFrame4();
}
}
Jen