Hi can someone take a look at this and help me to figure out how to fix the code? I am using netbeans (as a requirement) and am trying to get my mortgage calculator GUI to work. Im not necessarily getting errors but Im just not to sure what code I am missing because I am not getting any results. The GUI comes up and I am able to enter the loan amount, interest rate, and years but when I hit calculate I get no results.
package MortgageCalculator;
import javax.swing.JTextField;
/**
*
* @author
*/
public class MortgageCalculatorGUI extends javax.swing.JFrame {
/**
* Creates new form MortgageCalculatorGUI
*/
public MortgageCalculatorGUI() {
initComponents();
}
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
loanLabel = new javax.swing.JLabel();
interestLabel = new javax.swing.JLabel();
yearsLabel = new javax.swing.JLabel();
calculatejButton = new javax.swing.JButton();
clearjButton = new javax.swing.JButton();
exitjButton = new javax.swing.JButton();
loanAmountText = new javax.swing.JTextField();
interestRateText = new javax.swing.JTextField();
loanYearsText = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);
loanLabel.setText("Loan Amount");
interestLabel.setText("Interest Rate");
yearsLabel.setText("Loan Years");
calculatejButton.setText("Calculate");
calculatejButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
calculatejButtonActionPerformed(evt);
}
});
clearjButton.setText("Clear");
clearjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearjButtonActionPerformed(evt);
}
});
exitjButton.setText("Exit");
exitjButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitjButtonActionPerformed(evt);
}
});
loanAmountText.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loanAmountTextActionPerformed(evt);
}
});
interestRateText.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
interestRateTextActionPerformed(evt);
}
});
loanYearsText.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loanYearsTextActionPerformed(evt);
}
});
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setBorder(null);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(loanLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addComponent(loanAmountText, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(calculatejButton)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clearjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(yearsLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(interestLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.LEADING)
.addComponent(loanYearsText, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(interestRateText, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(28, 28, 28)
.addComponent(exitjButton, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(45, 45, 45))))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(49, 49, 49)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.Grou pLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(12, 12, 12)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.TRAILING)
.addComponent(loanLabel)
.addComponent(loanAmountText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(interestLabel)
.addComponent(interestRateText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(23, 23, 23)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(yearsLabel)
.addComponent(loanYearsText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(33, 33, 33)
.addGroup(jPanel1Layout.createParallelGroup(javax. swing.GroupLayout.Alignment.BASELINE)
.addComponent(calculatejButton)
.addComponent(clearjButton)
.addComponent(exitjButton))
.addGap(26, 26, 26)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(55, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 23, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 23, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_S IZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void exitjButtonActionPerformed(java.awt.event.ActionEv ent evt) {
System.exit(0);
}
private void clearjButtonActionPerformed(java.awt.event.ActionE vent evt) {
loanYearsText.setText(null);
loanAmountText.setText(null);
interestRateText.setText(null);
}
private void loanAmountTextActionPerformed(java.awt.event.Actio nEvent evt) {
}
private void interestRateTextActionPerformed(java.awt.event.Act ionEvent evt) {
}
private void loanYearsTextActionPerformed(java.awt.event.Action Event evt) {
}
private void calculatejButtonActionPerformed(java.awt.event.Act ionEvent evt) {
double loanAmount = 0.0;
double loanYears = 0.0;
double loanInterest = 0.0;
double monthlyPayment;
// Parse the text to a type double
loanAmount = Double.parseDouble(jTextArea1.getText());
loanYears = Double.parseDouble(jTextArea2.getText()); //I think this is wrong
loanInterest = Double.parseDouble(jTextField3.getText()); // I think this is wrong
// Perform the calculation
monthlyPayment = loanAmount * ( (loanInterest /100/12) / (1 - Math.pow((1+(loanInterest /100/12)),-1*(loanYears*12) ) ));
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
{
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClass Name());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MortgageCalcula torGUI.class.getName()).log(java.util.logging.Leve l.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MortgageCalcula torGUI.class.getName()).log(java.util.logging.Leve l.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MortgageCalcula torGUI.class.getName()).log(java.util.logging.Leve l.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MortgageCalcula torGUI.class.getName()).log(java.util.logging.Leve l.SEVERE, null, ex);
}
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MortgageCalculatorGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton calculatejButton;
private javax.swing.JButton clearjButton;
private javax.swing.JButton exitjButton;
private javax.swing.JLabel interestLabel;
private javax.swing.JTextField interestRateText;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField loanAmountText;
private javax.swing.JLabel loanLabel;
private javax.swing.JTextField loanYearsText;
private javax.swing.JLabel yearsLabel;
// End of variables declaration
}