Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Button wont trigger output in textarea

843789Jan 25 2010 — edited Jan 26 2010
I am doing something wrong here and cant figure out why my second set of buttons will not give output in my textarea. I would appreciate it if anyone could help shed some light on why its not working...
	 public void actionPerformed(ActionEvent e)//creates the action event
	 {
	 if(e.getSource() == calculateBtn)
	 {
	 if (loanSlctBx.getSelectedItem().equals("7 years at 5.35%"))//array used to selcted term and APR bassed on the Combo Box
	 				 {
	 					 apr=b[0];//tells to store the 1st value to the varible
	 					 term=a[0];
	 				 }
	 				 else if (loanSlctBx.getSelectedItem().equals("15 years at 5.5%"))
	 				 {
	 					 apr=b[1];
	 					 term=a[1];//tells to store the 2nd value to the varible
	 				 }
	 				 else if (loanSlctBx.getSelectedItem().equals("30 years at 5.75%"))
	 				 {
	 					 apr=b[2];//tells to store the 3rd value to the varible
	 					 term=a[2];
	 				 }

	 		 // Makes all the calculation needed for the output
	 	     amnt = Double.parseDouble(amntFld.getText());
	 	     amntFld.setText(currencyComposition(amnt)); // Formats the value to use a US currencey composistion
	 	     mTerm = term*12; //sets the mTerm variable
	 	     mApr = (apr / 100) / 12; //sets the mApr with the monthly interest
	  	     pay = amnt * (mApr / (1 - Math.pow((1 + mApr), -mTerm)));//sets the pay varible with the results
	 	     double newAmnt = amnt;//sets new variable for new loan amount
	          //Loop to run the calulations thorughout the life of the loan
	 	     for (int i=0; i<mTerm;i++)
	 	     {
	 			 if (i==36||i==72||i==108||i==144||i==180||i==216||i==252||i==288||i==326||i==360)
	 			 {
	 				 try
	 				 {
	 					 Thread.sleep(500);//sleep timer
	 				 }
	 				 catch (InterruptedException e1)
	 				 {
	 				 }
	 			 }
	 			 //Prints the output for the calculations in the JTextAera one line at a time
	 			 payFld.append(i+1 +"                        "+currencyComposition(pay)+"                       "+currencyComposition(newAmnt*mApr)+"                    "+currencyComposition(pay-(newAmnt*(mApr))) +"         "+currencyComposition(newAmnt)+"\n");
	 			 newAmnt -= pay-(newAmnt*(mApr));
	 		 }
	 	 }



	 if(e.getSource() == calculateBtn2)
	 {
		if (e.getActionCommand().equals(calculateBtn2.getActionCommand()))
		{
			String amnt2 = amntFld2.getText();
	 	    String term2 = termFld2.getText();
	 	    String apr2 = aprFld2.getText();
		}
		else if (e.getActionCommand().equals(resetBtn.getActionCommand())) // Resets all fields
		{
			amntFld2.setText(null);
			aprFld2.setText(null);
			termFld2.setText(null);
		    payFld.setText(null);
		}
	 	 // Makes all the calculation needed for the output
	 	 //amnt2 = Double.parseDouble(amntFld2.getText());
	 	 //amntFld2.setText(currencyComposition(amnt2)); // Formats the value to use a US currencey composistion
	 	 mTerm2 = term2*12; //sets the mTerm variable
	 	 mApr2 = (apr2 / 100) / 12; //sets the mApr with the monthly interest
	  	 pay = amnt2 * (mApr2 / (1 - Math.pow((1 + mApr2), -mTerm2)));//sets the pay varible with the results

	 	 double newAmnt2 = amnt2;//sets new variable for new loan amount

	     //Loop to run the calulations thorughout the life of the loan

	 	 for (int i=0; i<mTerm2;i++)
	 	     {
	 			 if (i==36||i==72||i==108||i==144||i==180||i==216||i==252||i==288||i==326||i==360)
	 			 {
	 				 try
	 				 {
	 					 Thread.sleep(500);//sleep timer
	 				 }
	 				 catch (InterruptedException e1)
	 				 {
	 				 }
	 			 }


	 			 //Prints the output for the calculations in the JTextAera one line at a time
	 			 payFld.append(i+1 +"                        "+currencyComposition(pay)+"                       "+currencyComposition(newAmnt2*mApr2)+"                    "+currencyComposition(pay-(newAmnt2*(mApr2))) +"         "+currencyComposition(newAmnt2)+"\n");
	 			 newAmnt2 -= pay2-(newAmnt2*(mApr2));
			 }
		 }
	 }

	 			// Formats the numeric values to readable currency
	 			private String currencyComposition(double input) {

	 			        DecimalFormat df = new DecimalFormat("$###,###,###.00");
	 			        df.setMaximumFractionDigits(2);
	 			        String formattedString = df.format(input);
	 			        return formattedString;
		}
	 }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2010
Added on Jan 25 2010
1 comment
122 views