This program is to design a gui for users to add any loan amount, term, and APR; the program then gives a monthly note amount in that field. I cannot figure out what I'm doing wrong. I also cannot get the reset button to work. Can anyone give me an idea of what I've done wrong?

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.DecimalFormat;


class BeemanWk2 extends JFrame {
	DecimalFormat Dollar = new DecimalFormat ("$###,###.00");


//Set up row 1
		private JLabel principalLabel = new JLabel("Loan Amount:  ");
	    private JTextField principalText = new JTextField(10);

//Set up row 2

	    private JLabel termLabel = new JLabel("Term: ");
	    private JTextField termText = new JTextField(10);


//Set up row 3

	    private JLabel rateLabel = new JLabel("APR: ");
	    private JTextField rateText = new JTextField(10);

//Set up row 4
	    private JLabel payAmtLabel = new JLabel ("Monthly Note: ");
	    private JTextField payAmtText = new JTextField (10);

	 public BeemanWk2() {

	    JButton btnCalculate = new JButton("Calculate");
	    JButton btnReset = new JButton("Reset");
	    JPanel content = new JPanel();
	    content.setLayout(new BoxLayout(content,BoxLayout.Y_AXIS));
	    content.add(principalLabel);
	    content.add(principalText);
	    content.add(termLabel);
	    content.add(termText);
	    content.add(rateLabel);
	    content.add(rateText);
	    content.add(payAmtLabel);
	    content.add(payAmtText);
	    content.add(btnCalculate);
	    content.add(btnReset);
	    setContentPane(content);
	    setTitle("Mortgage Payment Calculator");
	    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    pack();

	  }

	class btnCalculateListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			double principal = Double.parseDouble(principalText.getText());
			double term = Double.parseDouble(termText.getText());
			double rate = Double.parseDouble(rateText.getText());

			onButtonCalculate();
		}

		private void onButtonCalculate() {

		}
	}
	public static double calculatePayment(double principal, double rate, int term){
        double monthlyInt = rate / 12;
        double monthlyPayment = (principal * monthlyInt)
                    / (1 - Math.pow(1/ (1 + monthlyInt), term* 12)); //*Shows 1 monthly payment multiplied by 12 to make one complete year. 
        return  (monthlyPayment);

        class btnResetListener implements ActionListener
{
	public void actionPerformed(ActionEvent e)
	{


	}


	//Main Method
	public static void main(String[]args)
{
	BeemanWk2 window = new BeemanWk2();
	window.setVisible(true);
}
}

onButtonCalculate method has no code in it.
actionPerformed method in btnResetListener has no code in it.
You define action listeners, but you do not add them to the buttons.
(and maybe more like these?)

In brief, it doesn't work because you haven't finished coding it!

Seems to me, and it's been a few years, that I got something very similar in school and I was supposed to finish the code. Are you just posting what you got and hoping we will write the part you're supposed to finish?

Seems to me, and it's been a few years, that I got something very similar in school and I was supposed to finish the code. Are you just posting what you got and hoping we will write the part you're supposed to finish?

I actually had the code in, and once again, I do have the code in for the calculation part of the program. I don't know why I didn't leave it in when I sent it, it was just so full of errors that I deleted it.

Anyway, nothing I can do about that now, I'll have to figure it out on my own. Thanks anyway for trying.

Debora

Here is my code with the math formula for figuring the monthly payment. The monthly payment would be figured by the computer after users enter the loan amount, term, and rate amounts. The PayAmt field needs to be where the formula would place the monthly payment.

Can anyone help?

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.text.DecimalFormat;


class BeemanWk2 extends JFrame {
//Set up Dollar & Decimal Place Format
	DecimalFormat Dollar = new DecimalFormat ("$###,###.00");


//Set up row 1
		private JLabel principalLabel = new JLabel("Loan Amount:  ");
	    private JTextField principalText = new JTextField(10);

//Set up row 2

	    private JLabel termLabel = new JLabel("Term: ");
	    private JTextField termText = new JTextField(10);


//Set up row 3

	    private JLabel rateLabel = new JLabel("APR: ");
	    private JTextField rateText = new JTextField(10);

//Set up row 4
	    private JLabel payAmtLabel = new JLabel ("Monthly Note: ");
	    private JTextField payAmtText = new JTextField (10);

	 public BeemanWk2() {

	    JButton btnCalculate = new JButton("Calculate");
	    JButton btnReset = new JButton("Reset");
	    JPanel content = new JPanel();
	    content.setLayout(new BoxLayout(content,BoxLayout.Y_AXIS));
	    content.add(principalLabel);
	    content.add(principalText);
	    content.add(termLabel);
	    content.add(termText);
	    content.add(rateLabel);
	    content.add(rateText);
	    content.add(payAmtLabel);
	    content.add(payAmtText);
	    content.add(btnCalculate);
	    content.add(btnReset);
	    setContentPane(content);
	    setTitle("Mortgage Payment Calculator");
	    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    pack();

	  }

	class btnCalculateListener implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			double principal = Double.parseDouble(principalText.getText());
			int term = Integer.parseInt(termText.getText())*12;
			double rate = Double.parseDouble(rateText.getText())/12;
			

			onButtonCalculate();
		}

		public void onButtonCalculate() {

		}
	};
	
	
	
class btnResetListener implements ActionListener
{
	public void actionPerformed(ActionEvent e)
	{
		principalText.setText("");
		termText.setText("");
		rateText.setText("");
		payAmtText.setText("");
	}

	}


//Main Method
public static void main(String[]args)
{
	BeemanWk2 window = new BeemanWk2();
	window.setVisible(true);
}
}

Can anyone help?

What do you need explained?
Can you describe what is happening with your code, perhaps show the output and explain what is wrong with it and show what you want the output to be.

there are lots of mistakes,

1/ why not using JFormattedTextField

a/ formating NumberInstance correctly and doesn't care about Locale (if USD, JPY, EUR, :-) with endian number format too)

b/ currency instance returns $ by defalult

2/ again look at link that I posted, there you have runnable example

3/ don't reinvent the wheel

We have not yet learned about JFormattedTextFields. My instructor told me to layout the gui in JPanel using JTextField's. There are currently two of us working on this one project, and we have been working for about 7 days now, and getting no where.

Are you telling me that we cannot get it done using the JPanel/JTextFields?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.