0

I used Eclipse for the compilation errors, but I need this program to work in Java Ready 1.4. This is the error it shows for Eclipse:

Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem: 
at test.MortgageCalculator$1.actionPerformed(MortgageCalculator.java:97)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

I have tried using: nextButton.addActionListener (this); to call Action Listener and it still gives the same error.

package test;

import java.awt.*; //for Dimension
import javax.swing.*; //for GUI components
import java.awt.event.*; //for MessageListener

public class MortgageCalculator extends JFrame implements ActionListener
{

public String nameField, ageField, incomeField, priceField, downPayField, interestRateField, paymentField, amortField;


public MortgageCalculator ()
{ //Frame
    JFrame frame = new JFrame ();
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    frame.setSize (new Dimension (300, 250));
    frame.setTitle ("Mortgage Calculator");
    frame.getContentPane ().setLayout (new BorderLayout ());

    //User Information (Input) - Center Panel
    JPanel centerPanel = new JPanel (new GridLayout (16, 1));
    //Personal Information
    centerPanel.add (new JLabel ("Personal Information", SwingConstants.CENTER));
    centerPanel.add (new JLabel ("Full Name:"));
    final JTextField nameField = new JTextField ();
    centerPanel.add (nameField);
    centerPanel.add (new JLabel ("Your Age:"));
    final JTextField ageField = new JTextField ();
    centerPanel.add (ageField);
    centerPanel.add (new JLabel ("Yearly Income:"));
    final JTextField incomeField = new JTextField ();
    centerPanel.add (incomeField);
    centerPanel.add (new JLabel ());
    //Mortgage Information
    centerPanel.add (new JLabel ("Mortgage Information" , SwingConstants.CENTER));
    centerPanel.add (new JLabel ("Price of Property:"));
    final JTextField priceField = new JTextField ();
    centerPanel.add (priceField);
    centerPanel.add (new JLabel ("Down Payment:"));
    final JTextField downPayField = new JTextField ();
    centerPanel.add (downPayField);
    centerPanel.add (new JLabel ("Interest Rate (%):"));
    final JTextField interestRateField = new JTextField ();
    centerPanel.add (interestRateField);
    centerPanel.add (new JLabel ("Amortization Period (Years):"));
    frame.getContentPane ().add (centerPanel, BorderLayout.CENTER);

    //User Options (Input) - South Panel
    JPanel southPanel = new JPanel (new GridLayout (8, 3));
    //Payment Option
    southPanel.add (new JLabel ("Payment:"));
    southPanel.add (new JLabel ("Type in 1, 2 or 3"));
    southPanel.add (new JLabel ());
    southPanel.add (new JLabel ("1. Weekly"));
    southPanel.add (new JLabel ("2. Biweekly"));
    southPanel.add (new JLabel ("3. Monthly"));
    JTextField paymentField = new JTextField ();
    southPanel.add (paymentField);
    southPanel.add (new JLabel ());
    southPanel.add (new JLabel ());

    //Amortization Period Option
    southPanel.add (new JLabel ("Amortization Period:"));
    southPanel.add (new JLabel ("Type in 1, 2 or 3"));
    southPanel.add (new JLabel ());
    southPanel.add (new JLabel ("1. 20 years"));
    southPanel.add (new JLabel ("2. 25 years"));
    southPanel.add (new JLabel ("3. 30 years"));
    JTextField amortField = new JTextField ();
    southPanel.add (amortField);
    southPanel.add (new JLabel ());
    southPanel.add (new JLabel ());
    //To add a blank line in frame, added three blank JLabels because it is 3 horiontal for grid layout
    southPanel.add (new JLabel ());
    southPanel.add (new JLabel ());
    southPanel.add (new JLabel ());
    southPanel.add (new JButton ("Clear Information"));
    southPanel.add (new JLabel ());
    JButton nextButton = new JButton ("Next");
    southPanel.add (nextButton);

    frame.getContentPane ().add (southPanel, BorderLayout.SOUTH);


    frame.pack ();
    frame.setVisible (true);

    nextButton.addActionListener(new ActionListener () {

        public void actionPerformed (ActionEvent e) {

            //Gets the personal information from the text fields
            String name;
            int age, payment, amort;
            double income, price, downPay, interestRate;

            name = nameField.getText();
            age = Integer.parseInt (ageField.getText ());
            income = Double.parseDouble (incomeField.getText ());
            price = Double.parseDouble (priceField.getText ());
            downPay = Double.parseDouble (downPayField.getText ());
            interestRate = Double.parseDouble (interestRateField.getText ());
            payment = Integer.parseInt (paymentField.getText ());
            amort = Integer.parseInt (amortField.getText ());

            interestRate = interestRate / 100;      


            //Output frame
            JFrame frame2 = new JFrame ();
            frame2.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
            frame2.setSize (new Dimension (300, 250));
            frame2.setTitle ("Mortgage Calculator");
            frame2.getContentPane ().setLayout (new BorderLayout ());

            JPanel westPanel2 = new JPanel (new GridLayout (3, 1));
            JLabel nameLabel = new JLabel ("Name: " + name);
            westPanel2.add (nameLabel);
            JLabel ageLabel = new JLabel ("Age: " + age);
            westPanel2.add (ageLabel);
            JLabel incomeLabel = new JLabel ("Yearly Income: $" + income);
            westPanel2.add (incomeLabel);
            frame2.getContentPane ().add (westPanel2, BorderLayout.WEST);

            JPanel centerPanel2 = new JPanel (new GridLayout (3, 1));
            JLabel priceLabel = new JLabel ("    Price of property: $" + price);
            centerPanel2.add (priceLabel);
            JLabel downPayLabel = new JLabel ("    Down Payment: $" + downPay);
            centerPanel2.add (downPayLabel);
            JLabel interestRateLabel = new JLabel ("    Interest Rate: " + income);
            centerPanel2.add (interestRateLabel);
            frame2.getContentPane ().add (centerPanel2, BorderLayout.CENTER);


            double interest, numerator, l, denominator, payPerPeriod, initialP, mortgageYearly;
            if (payment == 1)
            {
                interest = 1 + interestRate / 52;
                if (amort == 1)
                {
                    l = Math.pow (interest, 20 * 52);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;
                }
                else if (amort == 2)
                {
                    l = Math.pow (interest, 25 * 52);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;
                }
                else // 3. amort30
                {
                    l = Math.pow (interest, 30 * 52);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;
                }
                mortgageYearly = payPerPeriod * 52;
            }
            else if (payment == 2)
            {
                interest = 1 + interestRate / 26;
                if (amort == 1)
                {
                    l = Math.pow (interest, 20 * 26);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;
                }
                else if (amort == 2)
                {
                    l = Math.pow (interest, 25 * 26);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;
                }
                else // 3. amort30
                {
                    l = Math.pow (interest, 30 * 26);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;
                }
                mortgageYearly = payPerPeriod * 26;


            }
            else //3. monthly payment
            {
                interest = 1 + interestRate / 12;
                if (amort == 1)
                {
                    l = Math.pow (interest, 20 * 12);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;
                }
                else if (amort == 2)
                {
                    l = Math.pow (interest, 25 * 12);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;
                }
                else // 2. amort30
                {
                    l = Math.pow (interest, 30 * 12);
                    numerator = l * interest;
                    denominator = l - 1;
                    initialP = price - downPay;
                    payPerPeriod = (numerator / denominator) * initialP;

                }
                mortgageYearly = payPerPeriod * 12;
            }


            JPanel eastPanel2 = new JPanel (new GridLayout (3, 1));
            JLabel payTotalLabel = new JLabel ("    Payment Total: $" + initialP);
            eastPanel2.add (priceLabel);
            JLabel payPerPeriodLabel = new JLabel ("    Payment per period: $" + payPerPeriod);
            eastPanel2.add (payPerPeriodLabel);

            frame2.getContentPane ().add (eastPanel2, BorderLayout.EAST);


            JPanel southPanel2 = new JPanel (new GridLayout (2, 1));
            double minimumIncome = mortgageYearly / 0.28;
            JLabel minimumLabel = new JLabel ("    Minimum Yearly Income: $" + minimumIncome);
            eastPanel2.add (priceLabel);

            if (minimumIncome > income)
            {
                JLabel qualifiedLabel = new JLabel ("You are not qualified for the mortgage");
                eastPanel2.add (qualifiedLabel);
            }
            else
            {
                JLabel qualifiedLabel = new JLabel ("You are qualified for the mortgage");
                eastPanel2.add (qualifiedLabel);
            }


            frame2.getContentPane ().add (eastPanel2, BorderLayout.EAST);



            frame2.pack ();
            frame2.setVisible (true);



        }

    });

}


public static void main (String[] args)
{
    MortgageCalculator mainApp = new MortgageCalculator ();

}
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Anna L
  • 5
  • 1
  • 1
    *"I used eclipse for the compilation errors"* The thing is, you should use the warnings the compiler provides through Eclipse to **solve** the compilation errors, rather than ignore them to produce.. `java.lang.Error: Unresolved compilation problem:`! – Andrew Thompson Jun 13 '17 at 14:08
  • See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – Andrew Thompson Jun 13 '17 at 22:33

1 Answers1

1
public class MortgageCalculator extends JFrame implements ActionListener

Why do you say your class implements ActionListener?

You don't implement the ActionListener interface anywhere in your class so get rid of that declaration:

public class MortgageCalculator extends JFrame 
camickr
  • 321,443
  • 19
  • 166
  • 288
  • I have an Action Listener for the second JFrame in this class. – Anna L Jun 13 '17 at 20:38
  • Your MortgageCalculator does NOT implement ActionLIstener. Read your text book for more information on the "implements" keyword. Understanding this concept is Java 101. – camickr Jun 14 '17 at 01:41