Another Mortgage Calculator

Service Request 5

  • (2 Pages)
  • +
  • 1
  • 2

21 Replies - 2083 Views - Last Post: 27 July 2009 - 07:53 PM Rate Topic: -----

#1 gday21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-April 09

Another Mortgage Calculator

Posted 24 July 2009 - 06:46 PM

The program compiles and runs but nothing fuctions.

import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
 
				.addContainerGap(27,Short.MAX_VALUE))
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		/*//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); */
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}



Is This A Good Question/Topic? 0
  • +

Replies To: Another Mortgage Calculator

#2 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Re: Another Mortgage Calculator

Posted 24 July 2009 - 07:42 PM

Does the gui even show up?
Was This Post Helpful? 0
  • +
  • -

#3 gday21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-April 09

Re: Another Mortgage Calculator

Posted 24 July 2009 - 08:49 PM

View Postsyfran, on 24 Jul, 2009 - 06:42 PM, said:

Does the gui even show up?


Yes it shows for me, but when I click the Calculate button nothing happens.
Was This Post Helpful? 0
  • +
  • -

#4 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Re: Another Mortgage Calculator

Posted 24 July 2009 - 08:55 PM

private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
	   
		/*//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
	   
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); */
	}	


Your problem is here, see if you can find it.
Was This Post Helpful? 0
  • +
  • -

#5 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Another Mortgage Calculator

Posted 24 July 2009 - 09:00 PM

did you generate this using a drag and drop IDE??..coz its kinda hard to read
Was This Post Helpful? 0
  • +
  • -

#6 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Another Mortgage Calculator

Posted 24 July 2009 - 09:04 PM

View Postsyfran, on 24 Jul, 2009 - 09:55 PM, said:

Your problem is here, see if you can find it.


I found it. :D (I know you didn't mean me...but oh well)

You commented everything out...at least...there's nothing being done in the CalculationPerformed() method.

I edited this post because I'm a gigantic idiot...

This post has been edited by Locke: 24 July 2009 - 09:08 PM

Was This Post Helpful? 0
  • +
  • -

#7 gday21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-April 09

Re: Another Mortgage Calculator

Posted 26 July 2009 - 12:43 PM

View PostLocke, on 24 Jul, 2009 - 08:04 PM, said:

View Postsyfran, on 24 Jul, 2009 - 09:55 PM, said:

Your problem is here, see if you can find it.


I found it. :D (I know you didn't mean me...but oh well)

You commented everything out...at least...there's nothing being done in the CalculationPerformed() method.

I edited this post because I'm a gigantic idiot...


Ok fixed that problem buy now my complier can not find a symbol : variable temp_interest
Location:class MCalculatorGUI2
import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
 
				.addContainerGap(27,Short.MAX_VALUE))
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); 
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}


Was This Post Helpful? 0
  • +
  • -

#8 syfran  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 83
  • View blog
  • Posts: 1,103
  • Joined: 12-July 09

Re: Another Mortgage Calculator

Posted 26 July 2009 - 01:09 PM

View Postgday21, on 26 Jul, 2009 - 11:43 AM, said:

View PostLocke, on 24 Jul, 2009 - 08:04 PM, said:

View Postsyfran, on 24 Jul, 2009 - 09:55 PM, said:

Your problem is here, see if you can find it.


I found it. :D (I know you didn't mean me...but oh well)

You commented everything out...at least...there's nothing being done in the CalculationPerformed() method.

I edited this post because I'm a gigantic idiot...


Ok fixed that problem buy now my complier can not find a symbol : variable temp_interest
Location:class MCalculatorGUI2
import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
 
				.addContainerGap(27,Short.MAX_VALUE))
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); 
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}


You never declare temp_interest. That is your problem.
Was This Post Helpful? 0
  • +
  • -

#9 gday21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-April 09

Re: Another Mortgage Calculator

Posted 26 July 2009 - 01:59 PM

View Postsyfran, on 26 Jul, 2009 - 12:09 PM, said:

View Postgday21, on 26 Jul, 2009 - 11:43 AM, said:

View PostLocke, on 24 Jul, 2009 - 08:04 PM, said:

View Postsyfran, on 24 Jul, 2009 - 09:55 PM, said:

Your problem is here, see if you can find it.


I found it. :D (I know you didn't mean me...but oh well)

You commented everything out...at least...there's nothing being done in the CalculationPerformed() method.

I edited this post because I'm a gigantic idiot...


Ok fixed that problem buy now my complier can not find a symbol : variable temp_interest
Location:class MCalculatorGUI2
import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
 
				.addContainerGap(27,Short.MAX_VALUE))
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); 
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}


You never declare temp_interest. That is your problem.


ok
Was This Post Helpful? 0
  • +
  • -

#10 gday21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-April 09

Re: Another Mortgage Calculator

Posted 26 July 2009 - 03:42 PM

View Postgday21, on 26 Jul, 2009 - 12:59 PM, said:

View Postsyfran, on 26 Jul, 2009 - 12:09 PM, said:

View Postgday21, on 26 Jul, 2009 - 11:43 AM, said:

View PostLocke, on 24 Jul, 2009 - 08:04 PM, said:

View Postsyfran, on 24 Jul, 2009 - 09:55 PM, said:

Your problem is here, see if you can find it.


I found it. :D (I know you didn't mean me...but oh well)

You commented everything out...at least...there's nothing being done in the CalculationPerformed() method.

I edited this post because I'm a gigantic idiot...


Ok fixed that problem buy now my complier can not find a symbol : variable temp_interest
Location:class MCalculatorGUI2
import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
 
				.addContainerGap(27,Short.MAX_VALUE))
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); 
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}


You never declare temp_interest. That is your problem.


ok


I think I have temp-interest declared but it is still not working
import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
						.addComponent(temp_term))
 
				.addContainerGap(27,Short.MAX_VALUE));
				
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			temp_term,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); 
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}


Was This Post Helpful? 0
  • +
  • -

#11 gday21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-April 09

Re: Another Mortgage Calculator

Posted 27 July 2009 - 08:12 AM

View Postgday21, on 26 Jul, 2009 - 02:42 PM, said:

View Postgday21, on 26 Jul, 2009 - 12:59 PM, said:

View Postsyfran, on 26 Jul, 2009 - 12:09 PM, said:

View Postgday21, on 26 Jul, 2009 - 11:43 AM, said:

View PostLocke, on 24 Jul, 2009 - 08:04 PM, said:

View Postsyfran, on 24 Jul, 2009 - 09:55 PM, said:

Your problem is here, see if you can find it.


I found it. :D (I know you didn't mean me...but oh well)

You commented everything out...at least...there's nothing being done in the CalculationPerformed() method.

I edited this post because I'm a gigantic idiot...


Ok fixed that problem buy now my complier can not find a symbol : variable temp_interest
Location:class MCalculatorGUI2

I have this error


MCalculatorGUI2.java:101: illegal start of expression
		);
		^
1 error

import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
 
				.addContainerGap(27,Short.MAX_VALUE))
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); 
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}


You never declare temp_interest. That is your problem.


ok


I think I have temp-interest declared but it is still not working
import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
						.addComponent(temp_term))
 
				.addContainerGap(27,Short.MAX_VALUE));
				
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			temp_term,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); 
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}


Was This Post Helpful? 0
  • +
  • -

#12 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: Another Mortgage Calculator

Posted 27 July 2009 - 10:44 AM

View Postgday21, on 26 Jul, 2009 - 04:42 PM, said:

I think I have temp-interest declared but it is still not working


No....a declaration of a variable looks like this.

double temp_interest; <- Specifically that one
OR double temp_interest = SOME_VALUE; (this is definition and initialization. Initialization means giving it its first value)

You never did either of those. So you're trying to use a variable that does not exist.

This post has been edited by Locke: 27 July 2009 - 10:45 AM

Was This Post Helpful? 0
  • +
  • -

#13 gday21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-April 09

Re: Another Mortgage Calculator

Posted 27 July 2009 - 05:02 PM

View PostLocke, on 27 Jul, 2009 - 09:44 AM, said:

View Postgday21, on 26 Jul, 2009 - 04:42 PM, said:

I think I have temp-interest declared but it is still not working


No....a declaration of a variable looks like this.

double temp_interest; <- Specifically that one
OR double temp_interest = SOME_VALUE; (this is definition and initialization. Initialization means giving it its first value)

You never did either of those. So you're trying to use a variable that does not exist.

Ok now I am really lost!
import javax.swing.*;
 
 
//imported io file for the math method
import java.io.*;
//imported decimalformt for its format method
import java.text.DecimalFormat;
 
 
public class MCalculatorGUI2 extends javax.swing.JFrame
{
 
	/** Creating a new form MortgageCalGUI **/
	public MCalculatorGUI2()
	{
	int term = 0;
	double principal = 0;
	double rate = 0;
	double monthlyPayment = 0;
	double interest = 0;

		//call to method Components() to initilize the new from
		Components();
		
	}
 
	/** The Components() method is called within our MortgageCalGUI constructor to initilize our new MortgageCalGUI form **/
	private void Components()
	{
		//creating text fields
		txtfld_principal = new javax.swing.JTextField();
 
		//creating labels 
		//principal label field
		label_principal = new javax.swing.JLabel();
		label_principal.setText("Principal (No comma's)"); 
		//term label field
		label_term = new javax.swing.JLabel();
		label_term.setText("Select your term year: ");
		
		//create a combo box for our terms
		bx_term = new javax.swing.JComboBox(terms);
		bx_term.setSelectedIndex(0);
		
		/*
		create a monthly label to be used for monthly payment output
		label_monthly = new javax.swing.JLabel();
		label_monthly.setText("$0.00"); 
		*/
 
		//creating Button
		btn_calculate = new javax.swing.JButton();
		btn_calculate.setText("Calculate");
 
		//create out event handler for our combo box
		bx_term.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				HandleComboBox(evt);
			}
		});
		
		//create our event handler for our calculate button
		btn_calculate.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				CalculationPerformed(evt);
			}
		});		
		
		//create our "escape" route
		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		
		//create a new frame nameing it Mortgage Calculator
		JFrame frame = new JFrame("Mortgage Calculator");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //using our "escape" route for our new frame
		
		//set the layout of the window
		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
		getContentPane().setLayout(layout);
		
		/*** HORIZONTAL POSITION LAYOUT ***/
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD HORIZONTAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
					.addGroup(layout.createSequentialGroup()
						.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(label_principal))
 
				/* THE TERM LABEL FIELD HORIZONTOAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(label_term))
 
				/*** THE COMBO BOX HORIZONTAL POSITION ***/
					.addGroup(layout.createSequentialGroup()
						.addComponent(bx_term))
 
				/*** THE BUTTON HORIZONTAL POSITION ***/
						.addComponent(btn_calculate))
						.addComponent(temp_term))
 
				.addContainerGap(27,Short.MAX_VALUE));
				
		);
		
		layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { 
			btn_calculate,
			bx_term,
			txtfld_principal,
			temp_term,
			label_term }
		);
 
		/*** VERTICAL POSITION LAYOUT ***/
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
			.addGroup(layout.createSequentialGroup()
				.addContainerGap()
 
				/*** THE PRINCIPAL TEXT FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(txtfld_principal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
					.addComponent(label_principal))
 
				/*** THER TERM LABEL FIELD VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(label_term))
 
				/*** THE COMBO BOX VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(bx_term))
 
				/*** THE CALCULATE BUTTON VERTICAL POSITION ***/
				.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
					.addComponent(btn_calculate))
 
				.addContainerGap(21, Short.MAX_VALUE))
		);
		pack();
	}
	
	//HandleComboBox is called by the event handle for our combo box
	//Creates a temporary combo box to help set the arrays and to set the correct interest rates into the interest text field
	private void HandleComboBox(java.awt.event.ActionEvent evt)
	{
		//creating a temporary combo box
		//the source of our event is our combo box (bx_term)
		javax.swing.JComboBox temp_cb = (JComboBox)evt.getSource();
		
		//creating a temporary Sting to hold our selection from our combo box
		String temp_term = (String)temp_cb.getSelectedItem();
		txtfld_term.setText(temp_term + " years");
 
		//setting the index to our interest array
		int index = 0;
		switch((int)(Integer.parseInt(temp_term)))
		{
			case 7 :
				index = 0;
				break;
			case 15 :
				index = 1;
				break;
			case 30 :
				index = 2;
				break;
		}
		//using the index for our interest array
		txtfld_interest.setText(interest[index]+"");
	}
		
	//CalculationPerformed is called by the event handler for out button
	//calculates the inputed values and then updates the monthly payment label
	private void CalculationPerformed(java.awt.event.ActionEvent evt)
	{
		
		//calculate payment based on inputed values
		final double temp_mthly = (temp_principal * (temp_interest/12)) / (1-Math.pow(1 + temp_interest/12,-(temp_term*12)));
		
		label_monthly.setText(DecimalPlaces.format(temp_mthly) + " Monthly"); 
	}	
 
	public static void main(String[] args)
	{
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new MCalculatorGUI2().setVisible(true);
			}
		});
	}
 
	/*** VARIABLES AND OBJECT DECLARATIONS ***/
	//labels
	private javax.swing.JLabel label_principal;
	private javax.swing.JLabel label_term;
	private javax.swing.JLabel label_interest;
	private javax.swing.JLabel label_monthly;
	private javax.swing.JLabel label_pymntschedule;
	
	//text fields
	private javax.swing.JTextField txtfld_principal;
	private javax.swing.JTextField txtfld_term;
	private javax.swing.JTextField txtfld_interest;
	private javax.swing.JTextField txtfld_monthly;
	private javax.swing.JTextField txtfld_pymntschedule;
	
	//arrays
	private String[] terms	= { "7", "15", "30" };
	private double[] interest = { 0.0535, 0.055, 0.0575 };
	
	//buttons
	private javax.swing.JComboBox bx_term;
	private javax.swing.JButton btn_calculate;
 
	//scroll pane
	private javax.swing.JScrollPane scroll_payments;
 
	//Delcaing object
	//declaring "decimalPlaces" as a new object type of DecimalFormat with the format of 0.00
	//this ensures any vaiables used by decimalPlaces has a "currancy" value of two decimal places
	private DecimalFormat DecimalPlaces = new DecimalFormat("$#,###,###.##");
}


Was This Post Helpful? 0
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Another Mortgage Calculator

Posted 27 July 2009 - 06:21 PM

Avoid to repost the code at every reply
especially the code already posted in the previous reply
Nobody, or at least me, will bother scrolling down on all that code to go see the next question at the bottom
Was This Post Helpful? 0
  • +
  • -

#15 gday21  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 29
  • Joined: 26-April 09

Re: Another Mortgage Calculator

Posted 27 July 2009 - 06:46 PM

View Postpbl, on 27 Jul, 2009 - 05:21 PM, said:

Avoid to repost the code at every reply
especially the code already posted in the previous reply
Nobody, or at least me, will bother scrolling down on all that code to go see the next question at the bottom

Sorry about that.

View Postgday21, on 27 Jul, 2009 - 05:45 PM, said:

View Postpbl, on 27 Jul, 2009 - 05:21 PM, said:

Avoid to repost the code at every reply
especially the code already posted in the previous reply
Nobody, or at least me, will bother scrolling down on all that code to go see the next question at the bottom

Sorry about that.

Somebody help me out please.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2