<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "Event Handling"]]></title>
		<link>http://forums.hotjoe.com/posts/list/14.page</link>
		<description><![CDATA[Latest messages posted in the topic "Event Handling"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Event Handling</title>
				<description><![CDATA[ Hi<br /> <br /> I have to do a mortgage program using graphical user interface. The user can input any amount for the principal of the loan and then have three options for a payment plan. The program should display the mortgage payment then list the loan balance and interest paid for each payment over the life of the loan.<br /> <br /> I did the code but there is an event error and I cannot seem to understand why the error is there. The code is attached below. Any assistance would be appreciated.<br /> <br /> <br /> [code]<br /> <br /> import java.text.*;<br /> import java.awt.*;<br /> import java.io.*;<br /> import java.awt.event.*;<br /> import java.lang.Math.*;<br /> import javax.swing.*;<br /> <br /> public class MortgageCalcOptions extends JFrame implements ActionListener{<br /> <br /> 	<br />     //Declare variables & loan array and initialize with values<br />     //Declares the various button, text fields and labels for the calculator.<br />     <br /> 	JButton calculate, clear;       //Declares the calculate and clear data buttons.<br /> 	JTextField tmortgamt, tmortgpmt;           //Declares the text field for the mortgage amount.<br />         JLabel lmortgamt, lmortgage, lmortgpmt, lmortgdetails;     //Declares the label boxes for mortgage amount and mortgage details.<br />         JRadioButton select7, select15, select30;       //Declares the radio buttons to make term and interest rate selections<br />         JScrollPane backpanel;       //List of monthly payments and interest paid per month<br /> <br /> 	<br /> 	java.text.DecimalFormat dec = new java.text.DecimalFormat(",###.00");       //Decimal format<br />         <br />         <br />         int[] mortgtrm = {7, 15, 30};   //Initialises the array for the three different years.<br /> 	double[] mortgir = {5.35, 5.5, 5.75};   //Initialises the array for the three different interest rates.    <br />         double mortgamt = Double.parseDouble(tmortgamt.getText());<br /> <br /> <br />               <br />        //Sets constraints on the lay out of the interface of the calculator.<br />         <br />           public MortgageCalcOptions() {<br /> 			setLayout(new GridBagLayout());<br /> 			GridBagConstraints c = new GridBagConstraints();<br />     <br />         //Creating, formatting and position and orientation of each component on the calculator interface. <br />         //Set the size of the buttons, labels and text fields.<br /> 		<br />                         lmortgamt = new JLabel("Amount   ");<br />                         c.fill = GridBagConstraints.HORIZONTAL;<br />                         c.gridx = 0;<br />                         c.gridy = 0;<br />                         c.gridwidth = 1;<br />                         add(lmortgamt, c);<br />                         <br />                         tmortgamt = new JTextField(15);<br />                         c.fill = GridBagConstraints.HORIZONTAL;<br />                         c.gridx = 1;<br />                         c.gridy = 0;<br />                         c.gridwidth = 3;<br />                         add(tmortgamt, c);<br />                         <br />                         lmortgpmt = new JLabel("Payment   ");<br />                         c.fill = GridBagConstraints.HORIZONTAL;<br />                         c.gridx = 0;<br />                         c.gridy = 3;<br />                         c.gridwidth = 1;<br />                         add(lmortgpmt, c);<br />                         <br />                         tmortgpmt = new JTextField(15);<br />                         c.fill = GridBagConstraints.HORIZONTAL;<br />                         c.gridx = 1;<br />                         c.gridy = 3;<br />                         c.gridwidth = 3;<br />                         add(tmortgpmt, c);<br />                         <br />                         lmortgage = new JLabel("Mortgage Details    ");<br />                         c.fill = GridBagConstraints.HORIZONTAL;<br />                         c.gridx = 0;<br />                         c.gridy = 4;<br />                         c.gridwidth = 1;<br />                         add(lmortgage, c);<br />             <br />                         lmortgdetails = new JLabel("");<br />                         c.fill = GridBagConstraints.HORIZONTAL;<br />                         c.gridx = 0;<br />                         c.gridy = 5;<br />                         c.gridwidth = 1;<br />                         add(lmortgdetails, c);<br />                         <br />                         calculate = new JButton("Calculate");                        <br />                         c.fill = GridBagConstraints.HORIZONTAL;<br />                         c.gridx = 1;<br />                         c.gridy = 6;<br />                         c.gridwidth = 1;<br />                         add(calculate, c);<br />                         <br />                         clear = new JButton("Clear Data");                        <br />                         c.fill = GridBagConstraints.HORIZONTAL;<br />                         c.gridx = 2;<br />                         c.gridy = 6;<br />                         c.gridwidth = 1;<br />                         add(clear, c);<br />             <br />                         backpanel = new javax.swing.JScrollPane();<br />                         backpanel.setPreferredSize(new Dimension(300, 400));<br />                         backpanel.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);<br />                         backpanel.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));<br /> 		<br />                         select7 = new JRadioButton("7 Years at 5.35%", false);<br />                         select7.setActionCommand("sel7");<br /> 		<br />                         select15 = new JRadioButton("15 Years at 5.50%", false);<br />                         select15.setActionCommand("sel15");<br /> 		<br />                         select30 = new JRadioButton("30 Years at 5.75%", false);<br />                         select30.setActionCommand("sel30");<br /> <br /> 		<br />                         ButtonGroup group = new ButtonGroup();      //Create button group<br />                         group.add(select7);<br />                         group.add(select15);<br />                         group.add(select30);<br /> <br /> 		<br />         //Creates the event of the buttons calculate and clear data to perform.<br />         //The calculate button will calculate the mortgage payment and the clear data button will.<br />         //allow the user to clear the fields and enter new data.<br />                         <br />                         event a = new event();<br />                         calculate.addActionListener(a); <br />                         clear.addActionListener(a);<br />                         <br />                   }<br /> <br /> 	public void actionPerformed(ActionEvent a) { <br /> <br />                        <br />                 for (int i = 0; i &lt; mortgir.length; i++)<br /> {<br />                 // Formula to calculate one month's mortgage payment<br />                 double mortgpmt = (mortgamt * (mortgir[i]/12/100)) / (1-(Math.pow(1/(1+(mortgir[i]/12/100)),(mortgtrm[i]*12))));<br /> <br />                 // Formula to calculate the total amount paid over life of the loan<br />                 double tottobepd = (mortgtrm[i]*12) * mortgpmt;<br />          <br />                 // Formula to calculate the total interest paid over life of the loan<br />                 double totinttobepd = tottobepd - mortgamt;<br />         <br />                 //Declares and builds additional variables for caluclations<br />                 double mortgbal = mortgamt;<br />                 double balance = tottobepd;<br />                 double intbalance = totinttobepd;<br />                 double mortpdsofar = 0.0;<br />                 double intpaidsofar = 0.0;<br />                 double noofpayments = 0;<br />                 double intpdthismth;<br />         <br />        <br />         //When the calculate button is pressed the payment is calculated and shown in the payment field according to the mortgage plan.<br />         //Also when the clear data button is pressed all fields are set to null.<br /> 		<br />         String arg = event.getActionCommand();<br />         String op = a.getActionCommand();<br />         <br />              <br /> 		if(op.equals("Clear Data")) {<br /> 			tmortgamt.setText(null);<br /> 			tmortgpmt.setText(null);<br /> 			}<br /> <br />                 else if (op.equals("Calculate")) {<br />                 <br />                         if (arg == "sel7"){<br />                             double mortgamt = Double.parseDouble(tmortgamt.getText());<br />                             mortgpmt = (mortgamt * (mortgir[i]/12/100)) / (1-(Math.pow(1/(1+(mortgir[i]/12/100)),(mortgtrm[i]*12))));				<br />                             tmortgpmt.setText(""+ dec.format(mortgpmt));<br />                             lmortgdetails = new JLabel("Payment Number\tLoan Balance\t\tInterest");<br />                             <br />                             //This will start the loop statement and declares formula for loan balance and interest paid<br />                                 while (balance &gt; 0.0){<br /> <br /> 		}	<br />                                 intpdthismth = mortgbal * (mortgir[i]/12/100);<br />                                 mortgbal = mortgbal - (mortgpmt - intpdthismth);<br />                                 mortpdsofar = mortpdsofar + (mortgpmt - intpdthismth);<br />                                 intbalance = intbalance - intpdthismth;<br />                                 intpaidsofar = intpaidsofar + intpdthismth;<br />                                 balance = balance - mortgpmt;<br />                                 noofpayments = noofpayments + 1;<br />                    <br />                                 //Displays the loan balance and interest paid<br />                                 lmortgdetails = new JLabel(noofpayments+"\t\t"+"$" + dec.format(balance)+"\t\t"+"$" + dec.format(intpdthismth));<br />                     <br />                     }<br /> <br />                         if (arg == "sel15"){<br />                             double mortgamt = Double.parseDouble(tmortgamt.getText());<br />                             mortgpmt = (mortgamt * (mortgir[i]/12/100)) / (1-(Math.pow(1/(1+(mortgir[i]/12/100)),(mortgtrm[i]*12))));	<br />                             tmortgpmt.setText(""+ dec.format(mortgpmt));<br />                             lmortgdetails = new JLabel("Payment Number\tLoan Balance\t\tInterest");<br />                             <br />                             //This will start the loop statement and declares formula for loan balance and interest paid<br />                                 while (balance &gt; 0.0){<br /> <br /> 		}	<br />                                 intpdthismth = mortgbal * (mortgir[i]/12/100);<br />                                 mortgbal = mortgbal - (mortgpmt - intpdthismth);<br />                                 mortpdsofar = mortpdsofar + (mortgpmt - intpdthismth);<br />                                 intbalance = intbalance - intpdthismth;<br />                                 intpaidsofar = intpaidsofar + intpdthismth;<br />                                 balance = balance - mortgpmt;<br />                                 noofpayments = noofpayments + 1;<br />                    <br />                                 //Displays the loan balance and interest paid<br />                                 lmortgdetails = new JLabel(noofpayments+"\t\t"+"$" + dec.format(balance)+"\t\t"+"$" + dec.format(intpdthismth));<br /> 			<br />                     }<br />                    <br />                         if (arg == "sel30"){<br />                             double mortgamt = Double.parseDouble(tmortgamt.getText());<br />                             mortgpmt = (mortgamt * (mortgir[i]/12/100)) / (1-(Math.pow(1/(1+(mortgir[i]/12/100)),(mortgtrm[i]*12))));<br />                             tmortgpmt.setText(""+ dec.format(tmortgpmt));<br />                             lmortgdetails = new JLabel("Payment Number\tLoan Balance\t\tInterest");<br />                             <br />                             //This will start the loop statement and declares formula for loan balance and interest paid<br />                                 while (balance &gt; 0.0){<br /> <br /> 		}	<br />                                 intpdthismth = mortgbal * (mortgir[i]/12/100);<br />                                 mortgbal = mortgbal - (mortgpmt - intpdthismth);<br />                                 mortpdsofar = mortpdsofar + (mortgpmt - intpdthismth);<br />                                 intbalance = intbalance - intpdthismth;<br />                                 intpaidsofar = intpaidsofar + intpdthismth;<br />                                 balance = balance - mortgpmt;<br />                                 noofpayments = noofpayments + 1;<br />                    <br />                                 //Displays the loan balance and interest paid<br />                                 lmortgdetails = new JLabel(noofpayments+"\t\t"+"$" + dec.format(balance)+"\t\t"+"$" + dec.format(intpdthismth));<br /> <br />                     }<br />                 <br />                 }<br />             }<br />         }<br />         <br />         <br /> public static void main(String args[]) {<br />       <br />    //Sets the size of the calculator interface window, as well as set a lable for it.<br />    //And allows the user to close the window if so desired.<br />            <br />            <br />            MortgageCalcOptions gui = new MortgageCalcOptions();<br />            gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);<br />            gui.setVisible(true);<br />            gui.setSize(480,600);<br />            gui.setTitle("Mortgage Calculator");<br /> 		<br /> 	}<br /> }<br /> <br /> <br /> [/code]]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/3215/4501.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/3215/4501.page</link>
				<pubDate><![CDATA[Fri, 27 Jan 2012 19:34:21]]> GMT</pubDate>
				<author><![CDATA[ dakotasw]]></author>
			</item>
			<item>
				<title>Re:Event Handling</title>
				<description><![CDATA[ I forgot to add the error I am getting when I try to compile it. I am using NetBeans so the errors are already shown before I compile. The error is below:<br /> <br /> MortgageCalcOptions.java:131: error: cannot find symbol<br /> event a = new event();<br /> ^<br /> symbol: class event<br /> location: class MortgageCalcOptions<br /> MortgageCalcOptions.java:131: error: cannot find symbol<br /> event a = new event();<br /> ^<br /> symbol: class event<br /> location: class MortgageCalcOptions<br /> MortgageCalcOptions.java:164: error: cannot find symbol<br /> String arg = event.getActionCommand();<br /> ^<br /> symbol: variable event<br /> location: class MortgageCalcOptions<br /> 3 errors ]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/3215/4502.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/3215/4502.page</link>
				<pubDate><![CDATA[Sat, 28 Jan 2012 03:38:37]]> GMT</pubDate>
				<author><![CDATA[ dakotasw]]></author>
			</item>
			<item>
				<title>Re:Event Handling</title>
				<description><![CDATA[ Remember that Java is case sensitive - there is no event class but there is an Event class.<br /> <br /> And just some feedback - do yourself a favor and name your variables like a human is going to read your code.  It doesn't cost anything to name your variables in a way that makes sense - 'a' is far harder to figure out  than something like actionListenerEvent.]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/3215/4505.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/3215/4505.page</link>
				<pubDate><![CDATA[Mon, 30 Jan 2012 09:01:14]]> GMT</pubDate>
				<author><![CDATA[ stdunbar]]></author>
			</item>
			<item>
				<title>Event Handling</title>
				<description><![CDATA[ To help you out in the future, classes generally start with an Uppercase letter. Therefor, whenever you get an error like:<br /> <br /> symbol: class event <br /> location: class MortgageCalcOptions <br /> MortgageCalcOptions.java:131: error: cannot find symbol <br /> event a = new event(); <br /> ^ <br /> <br /> see that they are talking about "class event". This should tell you that "event" should be "Event".]]></description>
				<guid isPermaLink="true">http://forums.hotjoe.com/posts/preList/3215/4607.page</guid>
				<link>http://forums.hotjoe.com/posts/preList/3215/4607.page</link>
				<pubDate><![CDATA[Mon, 19 Mar 2012 14:42:34]]> GMT</pubDate>
				<author><![CDATA[ chowbaaron]]></author>
			</item>
	</channel>
</rss>
