Mortgage Calculator Help


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Mortgage Calculator Help

Threaded View

  1. #1
    Join Date
    Aug 2005
    Posts
    5

    Mortgage Calculator Help

    Hi I am taking a programming class and it requires me to write a java program to calculate mortgage with a GUI.
    Here is what I have so far. Where did I go wrong?

    Thanks in advance!
    Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    public class Calculator extends JFrame implements ActionListener {
    private JPanel panelAdder;
    private JLabel labela;
    private JLabel labelt;
    private JLabel labelr;
    private JTextField textFieldAmount;
    private JTextField textFieldTerm;
    private JTextField textFieldRate;
    private JTextField textFieldResult;
    private JButton buttonCalc;
    
    public Calculator() {
      initComponents();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
      pack();
    
      // Add Listeners
      buttonCalc.addActionListener(this);
    }
    
    public void initComponents() {
     //Initialize Components
     panelAdder = new JPanel();
     labela = new JLabel("Amount");
     textFieldAmount = new JTextField();
     labelt = new JLabel("Term");
     textFieldTerm = new JTextField();
     labelr = new JLabel("Rate");
     textFieldRate = new JTextField();
     textFieldResult = new JTextField();
     buttonCalc = new JButton("Calculate");
    
     //Set Object Attributes
     textFieldResult.setEditable(false);
     textFieldResult.setColumns(8);
     textFieldAmount.setColumns(6);
     textFieldTerm.setColumns(2);
     textFieldRate.setColumns(2);
    
     Container contentPane = getContentPane();
     contentPane.setLayout(new FlowLayout());
    
     //Lets add the components to the panel
     panelAdder.add(labela);
     panelAdder.add(textFieldAmount);
     panelAdder.add(labelt);
     panelAdder.add(textFieldTerm);
     panelAdder.add(labelr);
     panelAdder.add(textFieldRate);
     panelAdder.add(buttonCalc);
     panelAdder.add(textFieldResult);
    
     contentPane.add(panelAdder);
    }
    
    public static void main(String[] args) {
      Calculator frame = new Calculator();
    }
    
    private void setResultValue() {
       double amount = Integer.parseInt(textFieldAmount.getText());
       double term = Integer.parseInt(textFieldTerm.getText());
       double rate = Integer.parseInt(textFieldRate.getText()) / 100.;
       double result = amount * ( rate * Math.pow ( ( 1 + rate ), term ) ) / ( Math.pow( ( 1 + rate ), term ) - 1 );
    
       textFieldResult.setText(Double.toString(result));
    }
    
    public void actionPerformed(ActionEvent event) {
      System.out.println("Action Button");
      String command = event.getActionCommand();
      if (command == "Calculate") {
          setResultValue();
      }
    }
    }
    Last edited by vwrado; 09-06-2005 at 12:57 PM.

Similar Threads

  1. Mortgage Calculator Help Requested
    By Richbezza in forum C++
    Replies: 3
    Last Post: 05-09-2007, 02:16 AM
  2. Mortgage Calculator
    By phamber in forum ASP.NET
    Replies: 1
    Last Post: 07-22-2005, 08:55 AM
  3. PowerBuilder project - Mortgage Industry
    By kremburlee in forum Careers
    Replies: 0
    Last Post: 06-29-2005, 03:36 PM
  4. Mortgage Calc - URGENT Help
    By chadonline in forum Java
    Replies: 1
    Last Post: 06-06-2005, 06:39 AM
  5. Mortgage Calcutator
    By Eric Dillard in forum Java
    Replies: 0
    Last Post: 06-06-2002, 10:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center