on line 40 I have:

public void start

That is the only thing that is showing something wrong. I have addad, curly brackets with no luck and when I put a semi colon at the end everything after it shows an error. The programs opens the applet but does not initialize it.

Any suggestions??? :icon_question:

import java.awt.*;
import java.awt.event.*;

import javax.swing.AbstractButton;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class MortgageCalculator2 extends JApplet
implements ActionListener
{

private static final String Total = null;
JLabel MortgageCalculator = new JLabel("Mortgage Calculator");
JLabel principal = new JLabel("Principal");
JLabel interest = new JLabel ("Interest");
JLabel term = new JLabel ("Term");
JButton calcButton = new JButton ("Calculate");

{
		{
			final Container con = getContentPane();
			con.setLayout(new FlowLayout());
			final Font bigFont = null;
			MortgageCalculator.setFont(bigFont);
			con.add(MortgageCalculator);
			con.add(calcButton);
			calcButton.addActionListener(this);
			con.add(principal);
			con.add(interest);
			con.add(term);
			final Component totalResult = null;
			con.add(totalResult);
			
		}
	{
public void start
{
	principal.setText(principal);
	interest.setText(interest);
	term.setText(payment);
	totalResult.setText(Total);
	repaint();
}
		{
public void actionPerformed;ActionEvent e;
{
	Object source = e.getSource();
		if (source == calcButton)
		{
			String Response = JOptionPane.showInputDialog(null,"Enter amount of principal");
			String Response = JOptionPane.showInputDialog(null,"Enter amount of interest");
			String Response = JOptionPane.showInputDialog(null,"Enter amount of term");
			int[] principalLimit = {200000};
			int[] interestLimit = {5.35, 5.5, 5.75};
			int[] termLimit = {7, 15, 30};
			int principal = Integer.parseInt(response);
			int principlalFee = 0; int interestFee = 0; int termFee = 0;
			int x=0, a=0;
		}
		for (x = 200000; x>=0; --x)
			if (amount >= principal[x])
				principal = principal[x];
				payment = ((principal * Math.pow(1.0 + workRate, years * 12) * workRate) / (Math.pow(1.0 + workRate, years * 12) -1));
				x = 0;
				
				principal.setText("$ + principal + interest");
				totalResult.setText(" payment $" + payment);		
}

 }
}
		}

@Override
public void actionPerformed(final ActionEvent arg0) {
	// TODO Auto-generated method stub
	
}
}

Dani AI

Generated

The immediate compile failure comes from basic syntax and structural problems (unbalanced braces, method headers without (), and code placed outside methods). correctly pointed out the missing parentheses on start(), and ’s cleaned formatting shows how much those structural fixes help. Focus first on getting a minimal skeleton to compile, then add the mortgage logic.

Checklist to get a working baseline

  • Fix all method declarations so they include () and a body ({ ... }).
  • Replace the scattered instance-initializer blocks with a single init() that builds the UI; keep event handlers in actionPerformed.
  • Use distinct names for components vs. data (for example lblPrincipal and principalValue) so you do not declare a JLabel and an int with the same name.
  • Use the correct types: interest rates should be double[], parse user input with Double.parseDouble(...) inside a try/catch for NumberFormatException.
  • Remove or declare all undefined identifiers (amount, workRate, years, payment, etc.). Fix loops so you iterate over array indices, not unlikely numeric ranges like for (x = 200000; x >= 0; --x) that assume an array of that size.

Common semantic mistakes seen in the thread

  • Shadowing: having JLabel principal and later int principal will not compile.
  • Array/type mismatches: e.g., putting 5.35 into an int[].
  • Building UI outside lifecycle methods: use init() (create components), start() only if you need to resume activity. Note that applets are deprecated in modern Java—consider a JFrame/Swing application if running in a desktop environment.

A minimal, original skeleton to compile and demonstrate proper structure:

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

public class MortgageCalculator2 extends JApplet implements ActionListener {
    private JLabel lblPrincipal = new JLabel("Principal:");
    private JTextField txtPrincipal = new JTextField(8);
    private JButton btnCalc = new JButton("Calculate");
    private JLabel lblResult = new JLabel();

    public void init() {
        Container c = getContentPane();
        c.setLayout(new FlowLayout());
        c.add(lblPrincipal);
        c.add(txtPrincipal);
        c.add(btnCalc);
        c.add(lblResult);
        btnCalc.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        if (e.getSource() != btnCalc) return;
        try {
            double principal = Double.parseDouble(txtPrincipal.getText());
            double rate = 0.05 / 12; // example
            int months = 30 * 12;
            double payment = (principal * rate) / (1 - Math.pow(1 + rate, -months));
            lblResult.setText(String.format("Payment: $%.2f", payment));
        } catch (NumberFormatException ex) {
            JOptionPane.showMessageDialog(this, "Enter a valid number");
        }
    }
}

Fix the first syntax error reported by the compiler, recompile, and repeat—each subsequent fix will be much clearer.

Recommended Answers

All 6 Replies

You're missing the parenthesis

public void start(){

on that method and another after it.

on line 40 I have:

public void start

That is the only thing that is showing something wrong. I have addad, curly brackets with no luck and when I put a semi colon at the end everything after it shows an error. The programs opens the applet but does not initialize it.

Any suggestions??? :icon_question:

import java.awt.*;
import java.awt.event.*;

import javax.swing.AbstractButton;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class MortgageCalculator2 extends JApplet
implements ActionListener
{

private static final String Total = null;
JLabel MortgageCalculator = new JLabel("Mortgage Calculator");
JLabel principal = new JLabel("Principal");
JLabel interest = new JLabel ("Interest");
JLabel term = new JLabel ("Term");
JButton calcButton = new JButton ("Calculate");

{
		{
			final Container con = getContentPane();
			con.setLayout(new FlowLayout());
			final Font bigFont = null;
			MortgageCalculator.setFont(bigFont);
			con.add(MortgageCalculator);
			con.add(calcButton);
			calcButton.addActionListener(this);
			con.add(principal);
			con.add(interest);
			con.add(term);
			final Component totalResult = null;
			con.add(totalResult);
			
		}
	{
public void start
{
	principal.setText(principal);
	interest.setText(interest);
	term.setText(payment);
	totalResult.setText(Total);
	repaint();
}
		{
public void actionPerformed;ActionEvent e;
{
	Object source = e.getSource();
		if (source == calcButton)
		{
			String Response = JOptionPane.showInputDialog(null,"Enter amount of principal");
			String Response = JOptionPane.showInputDialog(null,"Enter amount of interest");
			String Response = JOptionPane.showInputDialog(null,"Enter amount of term");
			int[] principalLimit = {200000};
			int[] interestLimit = {5.35, 5.5, 5.75};
			int[] termLimit = {7, 15, 30};
			int principal = Integer.parseInt(response);
			int principlalFee = 0; int interestFee = 0; int termFee = 0;
			int x=0, a=0;
		}
		for (x = 200000; x>=0; --x)
			if (amount >= principal[x])
				principal = principal[x];
				payment = ((principal * Math.pow(1.0 + workRate, years * 12) * workRate) / (Math.pow(1.0 + workRate, years * 12) -1));
				x = 0;
				
				principal.setText("$ + principal + interest");
				totalResult.setText(" payment $" + payment);		
}

 }
}
		}

@Override
public void actionPerformed(final ActionEvent arg0) {
	// TODO Auto-generated method stub
	
}
}

OK I put in the () at the end and I am unsure of the second place you mean. It is still showing an error there. Thank you so much for helping me!

import java.awt.*;
import java.awt.event.*;

import javax.swing.AbstractButton;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class MortgageCalculator2 extends JApplet
implements ActionListener
{

private static final String Total = null;
JLabel MortgageCalculator = new JLabel("Mortgage Calculator");
JLabel principal = new JLabel("Principal");
JLabel interest = new JLabel ("Interest");
JLabel term = new JLabel ("Term");
JButton calcButton = new JButton ("Calculate");

{
		{
			final Container con = getContentPane();
			con.setLayout(new FlowLayout());
			final Font bigFont = null;
			MortgageCalculator.setFont(bigFont);
			con.add(MortgageCalculator);
			con.add(calcButton);
			calcButton.addActionListener(this);
			con.add(principal);
			con.add(interest);
			con.add(term);
			final Component totalResult = null;
			con.add(totalResult);
			
		}
	{
public void start ()
{
	principal.setText(principal);
	interest.setText(interest);
	term.setText(payment);
	totalResult.setText(Total);
	repaint();
}
		{
public void actionPerformed;ActionEvent e;
{
	Object source = e.getSource();
		if (source == calcButton)
		{
			String Response = JOptionPane.showInputDialog(null,"Enter amount of principal");
			String Response = JOptionPane.showInputDialog(null,"Enter amount of interest");
			String Response = JOptionPane.showInputDialog(null,"Enter amount of term");
			int[] principalLimit = {200000};
			int[] interestLimit = {5.35, 5.5, 5.75};
			int[] termLimit = {7, 15, 30};
			int principal = Integer.parseInt(response);
			int principlalFee = 0; int interestFee = 0; int termFee = 0;
			int x=0, a=0;
		}
		for (x = 200000; x>=0; --x)
			if (amount >= principal[x])
				principal = principal[x];
				payment = ((principal * Math.pow(1.0 + workRate, years * 12) * workRate) / (Math.pow(1.0 + workRate, years * 12) -1));
				x = 0;
				
				principal.setText("$ + principal + interest");
				totalResult.setText(" payment $" + payment);		
}

 }
}
		}

@Override
public void actionPerformed(final ActionEvent arg0) {
	// TODO Auto-generated method stub
	
}
}

I just added it just like you showed me. and now I have all kinds of errors. I will start working through them!

The bracket problems are hard to find because the indentation is so haphazard. I tried to format the code in NetBeans, but it came out all weird. Either it had a lot of problems parsing it due to errors or my setting are wrong. Anyway, here's your code in Java code tags.

The first obvious problem is line 39. Presumably that bracket is supposed to be an ending bracket to the one on line 23. However, it is a starting bracket, not an ending bracket, so I imagine that screws up everything right there for the rest of the program.

Lines 25 - 36 - This code isn't inside of any function. Is it supposd to be?

Line 40 - If start is a function, it needs a parameter list, even if the parameter list is empty. It still needs parentheses ().

Ditto Line 49.

import java.awt.*;
import java.awt.event.*;

import javax.swing.AbstractButton;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class MortgageCalculator2 extends JApplet
implements ActionListener
{

private static final String Total = null;
JLabel MortgageCalculator = new JLabel("Mortgage Calculator");
JLabel principal = new JLabel("Principal");
JLabel interest = new JLabel ("Interest");
JLabel term = new JLabel ("Term");
JButton calcButton = new JButton ("Calculate");

{
		{
			final Container con = getContentPane();
			con.setLayout(new FlowLayout());
			final Font bigFont = null;
			MortgageCalculator.setFont(bigFont);
			con.add(MortgageCalculator);
			con.add(calcButton);
			calcButton.addActionListener(this);
			con.add(principal);
			con.add(interest);
			con.add(term);
			final Component totalResult = null;
			con.add(totalResult);
			
		}
	{
public void start
{
	principal.setText(principal);
	interest.setText(interest);
	term.setText(payment);
	totalResult.setText(Total);
	repaint();
}
		{
public void actionPerformed;ActionEvent e;
{
	Object source = e.getSource();
		if (source == calcButton)
		{
			String Response = JOptionPane.showInputDialog(null,"Enter amount of principal");
			String Response = JOptionPane.showInputDialog(null,"Enter amount of interest");
			String Response = JOptionPane.showInputDialog(null,"Enter amount of term");
			int[] principalLimit = {200000};
			int[] interestLimit = {5.35, 5.5, 5.75};
			int[] termLimit = {7, 15, 30};
			int principal = Integer.parseInt(response);
			int principlalFee = 0; int interestFee = 0; int termFee = 0;
			int x=0, a=0;
		}
		for (x = 200000; x>=0; --x)
			if (amount >= principal[x])
				principal = principal[x];
				payment = ((principal * Math.pow(1.0 + workRate, years * 12) * workRate) / (Math.pow(1.0 + workRate, years * 12) -1));
				x = 0;
				
				principal.setText("$ + principal + interest");
				totalResult.setText(" payment $" + payment);		
}

 }
}
		}

@Override
public void actionPerformed(final ActionEvent arg0) {
	// TODO Auto-generated method stub
	
}
}

Thank you sooo much, as you can see I am not sure what I am doing. I will try your suggestions and get back to you. Thank you again

You're welcome. I took your code and cleaned it up a bit. There's still stuff for you to do and it won't compile, but there are fewer errors, the brackets are a little more reasonable, some of the variable types work better, the capitalization follows the naming conventions a little more, and it's formatted. Like I said, there's still stuff for you to do, but hopefully this'll put you a little more on track.

import java.awt.*;
import java.awt.event.*;

import javax.swing.AbstractButton;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

@SuppressWarnings("serial")
public class MortgageCalculator2 extends JApplet implements ActionListener
{
    JLabel mortgageCalculatorLabel = new JLabel("Mortgage Calculator");
    JLabel principalLabel = new JLabel("Principal");
    JLabel interestLabel = new JLabel("Interest");
    JLabel termLabel = new JLabel("Term");
    JLabel totalResultLabel = new JLabel("Total Result");
    JButton calcButton = new JButton("Calculate");
    int total = 0;
    int principal = 0;
    int interest = 0;
    int payment = 0;

    public void init()
    {
        final Container con = getContentPane();
        con.setLayout(new FlowLayout());
        final Font bigFont = null;
        mortgageCalculatorLabel.setFont(bigFont);
        con.add(mortgageCalculatorLabel);
        con.add(calcButton);
        calcButton.addActionListener(this);
        con.add(principalLabel);
        con.add(interestLabel);
        con.add(termLabel);
        con.add(totalResultLabel);
    }

    public void start()
    {
        principalLabel.setText(Integer.toString(principal));
        interestLabel.setText(Integer.toString(interest));
        termLabel.setText(Integer.toString(payment));
        totalResultLabel.setText(Integer.toString(total));
        repaint();
    }

    public void actionPerformed(ActionEvent e)
    {
        Object source = e.getSource();
        if (source == calcButton)
        {
            String response = JOptionPane.showInputDialog(null, "Enter amount of principal");
            response = JOptionPane.showInputDialog(null, "Enter amount of interest");
            response = JOptionPane.showInputDialog(null, "Enter amount of term");
            int[] principalLimit =
            {
                200000
            };
            int[] interestLimit =
            {
                5.35, 5.5, 5.75
            };
            int[] termLimit =
            {
                7, 15, 30
            };

            principal = Integer.parseInt(response);
            int principlalFee = 0;
            int interestFee = 0;
            int termFee = 0;
            int x = 0, a = 0;

            for (x = 200000; x >= 0; --x)
            {
                if (amount >= principal[x])
                {
                    principal = principal[x];
                }
            }
            payment = ((principal * Math.pow(1.0 + workRate, years * 12) * workRate) / (Math.pow(1.0 + workRate, years * 12) - 1));
            x = 0;

            principalLabel.setText("$ + principal + interest");
            totalResultLabel.setText(" payment $" + payment);
        }
    }
}
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.