Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Problem with Listener/Event format

Posted on 2005-04-17
10
Medium Priority
?
212 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:rockybalboa
  • 3
  • 2
  • 2
7 Comments
 
LVL 92

Accepted Solution

by:
objects earned 252 total points
ID: 13803859
> calc.addActionListener.(this);

extra . in there, should be:

calc.addActionListener(this);
0
 
LVL 92

Expert Comment

by:objects
ID: 13803862
> answer.setText(pmt.getText);               //display payment

should be:

answer.setText(dec.format(pmt));               //display payment
0
 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 248 total points
ID: 13804261
Rocky Balboa ;)

>> setContentPane(pane);

- not needed.

>> setVisible(true);

Better to do that after adding all components to the content pane.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:rockybalboa
ID: 13850989
Thank you,
If I can figure out how to split points I am going to give you some too mayan.
Dan
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13852893
You can post a question in the Community support topic-area (http://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).
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 13873271
Thanks, Rom :)
0
 

Author Comment

by:rockybalboa
ID: 14628730
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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question