Link to home
Start Free TrialLog in
Avatar of rockybalboa
rockybalboaFlag for United States of America

asked on

Problem with Listener/Event format

I am having a problem setting up the Listener/Event operations in this code.  I will admit the rest of the code is not complete but it will no longer build.

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

public class SeeMort extends JFrame implements ActionListener
{
    JPanel row1 = new JPanel();    
    JLabel title = new JLabel("Mortgage Calculation Tool");    
    JPanel row2 = new JPanel();
    JLabel amt = new JLabel("Enter Loan Amount");
    JLabel blank1 = new JLabel("           ");
    JLabel term = new JLabel("Enter Term in Months");
    JLabel blank2 = new JLabel("           ");
    JLabel rate = new JLabel("Enter Percentage Rate");    
    JPanel row3 = new JPanel();
    TextField amtx= new TextField(8);
    TextField termx= new TextField(8);
    TextField ratex= new TextField(8);    
    JPanel row4 = new JPanel();
    Button calc = new Button("Calculate Payment");
    JPanel row5 = new JPanel();
    TextField answer= new TextField(14);
   
    public SeeMort()
    {
        super("Mortgage Calculator");
      setSize(550, 500);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
        GridLayout layout = new GridLayout(5, 5, 145, 45);
        Container pane = getContentPane();        
        pane.setLayout(layout);
        row2.add(title);
        row3.add(amt);
        row3.add(blank1);
        row3.add(term);
        row3.add(blank2);
        row3.add(rate);
        pane.add(row2);
        row4.add(amtx);
        row4.add(termx);
        row4.add(ratex);
        pane.add(row3);
        pane.add(row4);        
      pane.add(calc);
        calc.addActionListener.(this);
        row5.add(answer);
        pane.add(row5);
        setContentPane(pane);
    }
   
    public void actionPerformed(ActionEvent ev)
    {
        if(ev.getSource() == calc);
        {
            int amount = Integer.parseInt(amtx.getText());                        //init var for loan amt
            int term = Integer.parseInt(termx.getText());                              //init var for length of loan
            double pmt = 0;                             //init var for payment
            double rate = Double.parseDouble(ratex.getText());                        //init var for interest rate
            {
                rate = (rate/12);                       //divide annual rate to get monthly rate
                term = (term * 12);                     //multiply years to get length in months
                pmt= (amount * (rate)) / (1-Math.pow(1 + rate, - term));    //compute payment
            }
            java.text.DecimalFormat dec = new java.text.DecimalFormat(",###.00");               //format next output to dollars.cents
            answer.setText(pmt.getText);               //display payment
        }
    }
    public static void main(String[] args)
    {
        SeeMort frame = new SeeMort();
    }
}

This line:
calc.addActionListener.(this);
is saying "expected identifier" even though I think I have assigned one.

This line:
answer.setText(pmt.getText);
is saying double cannot be dereferenced.

Sorry for the format but I couldn't figure out how to add code tags to my post.
I appreciate any help.
Thanx,
Dan
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> answer.setText(pmt.getText);               //display payment

should be:

answer.setText(dec.format(pmt));               //display payment
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rockybalboa

ASKER

Thank you,
If I can figure out how to split points I am going to give you some too mayan.
Dan
You can post a question in the Community support topic-area (https://www.experts-exchange.com/Community_Support) and request the moderators for re-opening this question so that you can split points (once it is opened, you can do so by clicking on the 'Split Points' link which you will see above the Comment box).
Thanks, Rom :)
Sorry about the abandon.  I tried a couple of different times to get the points to split and it would never work.  I don't remember what my last step was but it is my fault that I didn't follow it to resolution.
Thanks to those who helped, they deserve both the points and the recognition.
Dan