I need a little help with this code, I cannot get it right, and i know it is something simple that i am missing. Can someone help me out please.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.text.NumberFormat;
public class week2 extends JFrame implements ActionListener
{
//declaring fields for GUI
JTextField mortgageAmountField, interestRateField, yearsTermField, monthlyPayField;JButton monthButton;
JFrame frame;
int buttonCount = 0;
DecimalFormat fmt = new DecimalFormat("0.00");
//assigning labels to the fields
JLabel mortgageAmountLabel = new JLabel("Mortgage Amount:");
JLabel interestRateLabel = new JLabel("Interest Rate:");
JLabel yearsTermLabel=new JLabel("Term (Years):");
JLabel monthlyPayLabel=new JLabel();
public week2()
{
//declaring the title of the program
frame = new JFrame("Mortgage Calculator");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//declaring panels 1 and 2
JPanel Panel1 = new JPanel();
JPanel Panel2 = new JPanel();
//assigning buttons to the panels
Panel1.add(mortgageAmountLabel);
mortgageAmountField = new JTextField(15);
Panel1.add(mortgageAmountField);
Panel1.add(interestRateLabel);
interestRateField = new JTextField(5);
Panel1.add(interestRateField);
Panel1.add(yearsTermLabel);
yearsTermField = new JTextField(5);
Panel1.add(yearsTermField);
Panel2.add(monthlyPayLabel);
monthlyPayField = new JTextField(5);
Panel2.add(monthlyPayField);
monthButton = new JButton("Reset");
monthButton.addActionListener(this);
Panel2.add(monthButton);
monthButton = new JButton("Exit");
monthButton.addActionListener(this);
Panel2.add(monthButton);
//setting up the quit button for the user to calculate the program
monthButton = new JButton("Calculate");
monthButton.addActionListener(this);
Panel2.add(monthButton);
//indicating the border layout of our frames
frame.getContentPane().add(Panel1, BorderLayout.NORTH);
frame.getContentPane().add(Panel2, BorderLayout.SOUTH);
frame.setSize(700, 100);
frame.setResizable(true);
frame.show();
}
//activating the action event so the user's input is taken
public void actionPerformed(ActionEvent event){
if(event.getSource() == monthButton)
public void mortgageCalc1() {
double ortgageAmount=Double.parseDouble(mortgageAmountField.getText()); //O= Original amount of loan-hard coded
double interestRate=Double.parseDouble(interestRateField.getText()); //I=Interest rate-hard coded
double yearsTerm=Double.parseDouble(yearsTermField.getText()); //T=Term of loan- hard coded
double monthlyPay = (mortgageAmount*(interestRate / 12))/ (1 - (Math.pow(1 / (1 + (interestRate / 12)), yearsTerm)));
mortgageCalc1 = new mortgageCalc1(this);
//display the monthly payment
monthlyPayLabel.setText("Your Monthly Payment will be: " + fmt.format(monthlyPay));
//continue with button actionlistener
buttonCount++;
}
}
public static void main(String[] args)
{
week2 cal = new week2();
}
}
//end of programming