Mortgage Payment GUI - Calculation Errors

package my.mortgagecalc;

/**
 Hello -

I'm very new to programming and I can't figure out what why the calculations are not working. I need to display a mortgage program that accepts a user inputs based on the interest, principal, term in years. (GUI). It also needs to handle input errors (non numeric) as well and I'm not sure how to do it. I wanted the Monthly Payment Amount to populate when the Calculate button is clicked. Unfortunately, I really need help pretty quickly. Please help!
Thank you in advance.*
 *
 */
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.lang.Math;
import java.util.*;

//declare contents
public class MortgageCalcUI extends javax.swing.JFrame{
 //declare variables
    int TermsInYears;
    double MortgagePrinciple;
    double InterestRate;
    double MortgagePaymentAmount;
   
 
    /** Creates new form MortgageCalcUI */
    public MortgageCalcUI() {
        initComponents();
    }
   
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
    private void initComponents() {
        jMortgageCalculator = new javax.swing.JPanel();
        jlblMortgagePrincipal = new javax.swing.JLabel();
        MortgagePrincipleText = new javax.swing.JTextField();
        jlblInterestRate = new javax.swing.JLabel();
        InterestRateText = new javax.swing.JTextField();
        jlblTermsInYears = new javax.swing.JLabel();
        TermsInYearsText = new javax.swing.JTextField();
        jlblMortgagePaymentAmount = new javax.swing.JLabel();
        MortgagePaymentAmountText = new javax.swing.JTextField();
        jCalculateButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jMortgageCalculator.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Mortgage Payment Calculator", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 14)));
        jlblMortgagePrincipal.setText("Mortgage Principle:");

        MortgagePrincipleText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MortgagePrincipleTextActionPerformed(evt);
            }
        });

        jlblInterestRate.setText("Interest Rate:");

        InterestRateText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                InterestRateTextActionPerformed(evt);
            }
        });

        jlblTermsInYears.setText("Terms in Years:");

        jlblMortgagePaymentAmount.setText("Mortgage Payment Amount:");

        MortgagePaymentAmountText.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MortgagePaymentAmountTextActionPerformed(evt);
            }
        });

        jCalculateButton.setText("Calculate");
        jCalculateButton.setActionCommand("Calculate");
        jCalculateButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCalculateButtonActionPerformed(evt);
            }
        });
        jCalculateButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jCalculateButtonMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jMortgageCalculatorLayout = new org.jdesktop.layout.GroupLayout(jMortgageCalculator);
        jMortgageCalculator.setLayout(jMortgageCalculatorLayout);
        jMortgageCalculatorLayout.setHorizontalGroup(
            jMortgageCalculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jMortgageCalculatorLayout.createSequentialGroup()
                .add(24, 24, 24)
                .add(jMortgageCalculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jlblInterestRate)
                    .add(jlblTermsInYears)
                    .add(jlblMortgagePaymentAmount)
                    .add(jlblMortgagePrincipal))
                .add(jMortgageCalculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jMortgageCalculatorLayout.createSequentialGroup()
                        .add(14, 14, 14)
                        .add(jCalculateButton))
                    .add(jMortgageCalculatorLayout.createSequentialGroup()
                        .add(25, 25, 25)
                        .add(jMortgageCalculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(MortgagePrincipleText)
                            .add(InterestRateText)
                            .add(TermsInYearsText)
                            .add(MortgagePaymentAmountText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))))
                .addContainerGap(89, Short.MAX_VALUE))
        );
        jMortgageCalculatorLayout.setVerticalGroup(
            jMortgageCalculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jMortgageCalculatorLayout.createSequentialGroup()
                .add(jMortgageCalculatorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jMortgageCalculatorLayout.createSequentialGroup()
                        .add(jlblMortgagePrincipal)
                        .add(16, 16, 16)
                        .add(jlblInterestRate)
                        .add(15, 15, 15)
                        .add(jlblTermsInYears)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 35, Short.MAX_VALUE)
                        .add(jlblMortgagePaymentAmount)
                        .add(13, 13, 13))
                    .add(jMortgageCalculatorLayout.createSequentialGroup()
                        .add(MortgagePrincipleText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(16, 16, 16)
                        .add(InterestRateText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(15, 15, 15)
                        .add(TermsInYearsText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 22, Short.MAX_VALUE)
                        .add(MortgagePaymentAmountText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)))
                .add(jCalculateButton)
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jMortgageCalculator, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jMortgageCalculator, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(99, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>

    private void MortgagePaymentAmountTextActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
        MortgagePaymentAmountText.setText("");
        System.out.println(MortgagePaymentAmountText.getText());
    }

    private void jCalculateButtonMouseClicked(java.awt.event.MouseEvent evt) {
     TermsInYears = Integer.parseInt(TermsInYearsText.getText());
     MortgagePrinciple = Double.parseDouble(MortgagePrincipleText.getText());
     Rate = Double.parseDouble(InterestRateText.getText());
     InterestRate = InterestRate / 100.0 / 12.0;
     MortgagePaymentAmount = MortgagePrinciple *(InterestRate/(1-Math.pow(InterestRate+1,-12.0*TermsInYears)));
     //format currency
     DecimalFormat currency = new DecimalFormat("$ ###,##0.00;$-###,##0.00"); //define currency format for numbers            
    }

    private void jCalculateButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
    }
 

    private void InterestRateTextActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
    }

    private void MortgagePrincipleTextActionPerformed(java.awt.event.ActionEvent evt) {
      // TODO add your handling code here:
    }
   
    /**
     * @param args the command line arguments
     */
      public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MortgageCalcUI().setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify
    private javax.swing.JTextField InterestRateText;
    private javax.swing.JTextField MortgagePaymentAmountText;
    private javax.swing.JTextField MortgagePrincipleText;
    private javax.swing.JTextField TermsInYearsText;
    private javax.swing.JButton jCalculateButton;
    private javax.swing.JPanel jMortgageCalculator;
    private javax.swing.JLabel jlblInterestRate;
    private javax.swing.JLabel jlblMortgagePaymentAmount;
    private javax.swing.JLabel jlblMortgagePrincipal;
    private javax.swing.JLabel jlblTermsInYears;
    // End of variables declaration
   
}
mpaytonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

InteractiveMindCommented:
>> needs to handle input errors (non numeric)


String input = component.getText() ; // Get input

boolean parsed = false ;
int value ;

try
{
    value = Integer.ParseInt( input ) ;
    parsed = true ;
} catch (Exception e)
{
    parsed = false ;
}
InteractiveMindCommented:
value = Integer.ParseInt( input ) ;

should be:

value = Integer.parseInt( input ) ;
                       ^
               Lower case 'p'
mpaytonAuthor Commented:
Thanks for the quick response! I will try this for the error handling. However, my calculation problem is still a problem for me. The applet runs, but the calculations are not functioning. Could you provide help in this area too!
InteractiveMindCommented:
Unfortunately, I do not have the jdesktop API, so I cannot try out your code myself.
(And by the way, it's an application -- not an applet)  :)

So, what problems are you having with your calculations exactly?

...If it's a case that nothing happens, then that'll be because you haven't updated your event methods, to actually preform the necessary calculations:

private void jCalculateButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
    }
 

    private void InterestRateTextActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
    }

    private void MortgagePrincipleTextActionPerformed(java.awt.event.ActionEvent evt) {
      // TODO add your handling code here:
    }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.