Here is my code so far. I'm not sure what I'm doing wrong, but I cannot get it to compile. Incompatible Types (Lines 90 - 92) . Please Please Help. My ultimate task is to write an Applet Mortgage Calculator.

import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.JOptionPane;


public class MortgageCalc extends JApplet implements ActionListener
{
Container con = getContentPane();



JLabel Greet = new JLabel("Estimate Mortgage Payments  \n");
Font headlineFontg = new Font("Helvetica", Font.BOLD, 28);


JLabel Mortgage = new JLabel ("Amount of Mortgage:                \n");
Font headlineFont = new Font("Helvetica", Font.BOLD, 12);
JTextField answer = new JTextField(10);



JLabel Interest= new JLabel("Interest Rate as % (e.g. 7.9):    \n");
Font headlineFonta = new Font("Helvetica", Font.BOLD, 12);
JTextField answera = new JTextField(10);


JLabel Time = new JLabel("Number of Years:                     \n");
Font headlineFontb = new Font("Helvetica", Font.BOLD, 12);
JTextField answerb = new JTextField(10);


JLabel MonthPay = new JLabel("Monthly Payment:                      \n");
Font headlineFontc = new Font("Helvetica", Font.BOLD, 12);
JTextField MoPay = new JTextField(10);


JLabel MonthPaya = new JLabel("  - -                                                     ");
Font headlineFontd = new Font("Helvetica", Font.BOLD, 12);



JButton Calculate = new JButton("Calculate");
JButton Reset = new JButton("Reset");



public void init()
{


Greet.setFont(headlineFontg);
con.add(Greet);


Mortgage.setFont(headlineFont);
con.add(Mortgage);
con.add(answer);
con.setLayout(new FlowLayout());
answer.addActionListener(this);


Interest.setFont(headlineFonta);
con.add(Interest);
con.add(answera);
con.setLayout(new FlowLayout());
answera.addActionListener(this);


Time.setFont(headlineFontb);
con.add(Time);
con.add(answerb);
con.setLayout(new FlowLayout());
answerb.addActionListener(this);


MonthPay.setFont(headlineFontc);
con.add(MonthPay);
con.add(MoPay);
con.setLayout(new FlowLayout());
MoPay.addActionListener(this);


MonthPaya.setFont(headlineFontd);
con.add(MonthPaya);
con.setLayout(new FlowLayout());



con.add(Calculate);
con.add(Reset);


}



public void actionPerformed(ActionEvent e)
{
int Mort;
int Int;
int T;



Mort = answer.getText();
Int = answera.getText();
T = answerb.getText();


MonthPay.setText( "$" + (Int - (Mort * Int * T)) / (T*12));



}


}

In the action performed method, include all of your current code inside of an if statement that checks which button was clicked.

Example:

if(e.getSource==<name of button>)
{
//CODE GOES HERE.
}

In the action performed method, include all of your current code inside of an if statement that checks which button was clicked.

Example:

if(e.getSource==<name of button>)
{
//CODE GOES HERE.
}

Also, make sure you added the actionlistener to the component.

Shouldn't these be parsed:

Mort = answer.getText();
Int = answera.getText();
T = answerb.getText();

MonthPay.setText( "$" + (Int - (Mort * Int * T)) / (T*12));

T = Integer.parseInt(answerb.getText());


Also, don't you want to use doubles?

Thanks. I do have the actionListener as part of the my beg header. I put the code into the brackets. I added the parse, which I figured that out after I asked the question. (Can you see, I'm new new to Java). Do you see anything else wrong with it. Now it is saying 'else' without 'if'????? Here is what I have now??

public void actionPerformed(ActionEvent e)
{


if(e.getSource()==Reset);


int Mort = 0;
int Int = 0;
int T = 0;


else if(e.getSource()==Calculate);
{
Mort = Integer.parseInt(answer.getText());
Int = Integer.parseInt(answera.getText());
T = Integer.parseInt(answerb.getText());


MonthPay.setText( "$" + (Int - (Mort * Int * T)) / (T*12));
}
}

Also to incorporate doubles- would I instead do;

double Mort = 0;
verses
int Mort = 0;

You have semi-colons after the if, and else statements. They shouldn't be there.

Thanks for all your help everyone!! I figured it out! It's working now, except rounding. But I'll get it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.