Question

Please Help!!!! Pass Variable to another class

Asked by: Kelela8

I know this is a stupid mistake but I am stuck and can't find it. I can't get my interestP and principalP variable to pass to the other class. I have slowly worked out my other problems. Now I have spent all day trying to figure this out and getting no where.

import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.text.*;
import java.util.*;
import java.lang.*;
import javax.swing.border.*;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JComponent;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import java.text.NumberFormat;
 
// Create MortgageCalculator class
public class MortCal5 extends JFrame implements ActionListener
{
	//declare variables
	double principle = 0.0;
	double interest = 0.0;
	int years = 0;
	double months = 0;
	int termArray[] = {7, 15, 30};
 
	double[] rates;
 
	private double intTotal = 0.0;
	private double priTotal = 0.0;
	private double payTotal = 0.0;
 
	 double interestP = 0.0;
	double principalP = 0.0;
 
	double[] values;
	private String[] names;
 
 
 
	JFrame f = new JFrame();
 
	// Text for Mortgage
	JPanel row1 = new JPanel(); // Sets up Panels, Preselect Buttons, and Frame.
	JLabel mortgageLabel = new JLabel("MORTGAGE PAYMENT CALCULATOR",
	JLabel.CENTER);
 
	JPanel row2 = new JPanel(new GridLayout(1, 2));
	JLabel principalLabel = new JLabel("Mortgage Amount $", JLabel.LEFT);
	JTextField principalText = new JTextField(10);
 
	JPanel row3 = new JPanel (new GridLayout(1, 2));
	JLabel termLabel = new JLabel("Mortgage Term (Years)", JLabel.LEFT);
	JTextField termText = new JTextField(3);
 
	JPanel row4 = new JPanel(new GridLayout(1,2));
	JLabel intRateLabel = new JLabel("Interest Rate (%)", JLabel.LEFT);
	JTextField intRateText = new JTextField(5);
 
	JPanel row5 = new JPanel(new GridLayout(1,2));
	JLabel paymentLabel = new JLabel("Monthly Payment $", JLabel.LEFT);
	JTextField paymentText = new JTextField(10);
 
	JPanel row6 = new JPanel(new GridLayout (1, 4));
	JLabel payLabel = new JLabel("Payment", JLabel.LEFT);
	JLabel prinLabel = new JLabel("", JLabel.LEFT);//Left for spacing and future needs
	JLabel intLabel = new JLabel("Interest", JLabel.LEFT);
	JLabel balLabel = new JLabel("Balance", JLabel.LEFT);
 
	// Create buttons to calculate payment, clear payment field and exit program
	JPanel radioPanel = new JPanel();
	JRadioButton button7 = new JRadioButton("7 Years at 5.35%", false);
	JRadioButton button15 = new JRadioButton("15 Years at 5.50%", false);
	JRadioButton button30 = new JRadioButton("30 Years at 5.75%", false);
 
	JPanel button = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 10));
	JButton calculateButton = new JButton("CALCULATE");
	JButton clearButton = new JButton("CLEAR");
	JButton exitButton = new JButton("EXIT");
 
	JTextArea displayArea = new JTextArea(10, 30);
	JScrollPane scroll = new JScrollPane(displayArea);
 
	JTextArea graphArea = new JTextArea (10, 30);
 
	JButton graphButton = new JButton("DISPLAY GRAPH");
 
	//sets decimal format
	DecimalFormat dollarAmount = new DecimalFormat("0.00");
    DecimalFormat percentAmount = new DecimalFormat("##.##");
 
    DataInputStream istream;
 
	//constructor Builds and displays GUI
	public void frame1()
	{
		this.setTitle("Mortgage Calculator");
		setSize(450, 450);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Container pane = getContentPane();
		getRates();
 
		Border rowboarder = new EtchedBorder();
 
		pane.add(row1);
		row1.add(mortgageLabel);
		row1.setMaximumSize(new Dimension (10000, row1.getMinimumSize().height));
 
		pane.add(row2);
		row2.add(principalLabel);
		row2.add(principalText);
		row2.setMaximumSize(new Dimension (10000, row2.getMinimumSize().height));
		principalText.setText("200000");
 
		pane.add(row3);
		row3.add(termLabel);
		row3.add(termText);
		row3.setMaximumSize(new Dimension (10000, row3.getMinimumSize().height));
		termText.setEditable(false);
		termText.setText("30");
 
		pane.add(row4);
		row4.add(intRateLabel);
		row4.add(intRateText);
		row4.setMaximumSize(new Dimension (10000, row4.getMinimumSize().height));
		intRateText.setEditable(false);
		intRateText.setText("5.75");
 
		// set Radio Buttons as group so only one can be selected
		ButtonGroup buttonGrp = new ButtonGroup();
		buttonGrp.add(button7);
		buttonGrp.add(button15);
		buttonGrp.add(button30);
 
		//add radio buttons to GUI
		radioPanel.add(button7);
		radioPanel.add(button15);
		radioPanel.add(button30);
		pane.add(radioPanel);
		radioPanel.setMaximumSize(new Dimension(10000,
		radioPanel.getMinimumSize().height));
 
		pane.add(row5);
		row5.add(paymentLabel);
		row5.add(paymentText);
		row5.setMaximumSize(new Dimension (10000, row5.getMinimumSize().height));
		paymentText.setEditable(false);
 
		// Add Buttons for calculate, clear, and exit
		button.add(calculateButton);
		button.add(clearButton);
		button.add(exitButton);
		pane.add(button);
 
		// Add Listeners to buttons
		calculateButton.addActionListener(this);
		clearButton.addActionListener(this);
		exitButton.addActionListener(this);
		button7.addActionListener(this);
		button15.addActionListener(this);
		button30.addActionListener(this);
		graphButton.addActionListener(this);
 
		//Add labels above text box (Amortization)
		pane.add(row6);
		row6.add(payLabel);
		row6.add(balLabel);
		row6.add(intLabel);
		row6.add(prinLabel);//added for spacing and future need
		row6.setMaximumSize(new Dimension (10000, row6.getMinimumSize().height));
 
		pane.add(row6);
 
		scroll.setBorder(BorderFactory.createEtchedBorder());
 
		pane.add(scroll);
 
		pane.add(graphButton);
 
		pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
		setContentPane(pane);
		setVisible(true);
 
	}
	//Main method
	public static void main(String[] args)throws ParseException
	{
    	MortCal5 frame = new MortCal5();
    	frame.frame1();
 
    }
 
	//opens the rates.txt file and reads the interest rates into the array
	public void getRates()
	{
	    try
	    {
	      ArrayList<String> arrayRates = new ArrayList<String>();
 
	      BufferedReader inputfile = new BufferedReader(new FileReader("rates.txt"));
	      String data;
 
	      while ((data = inputfile.readLine()) != null)
	      {
	        System.out.println(data);
	        arrayRates.add(data);
	      }
 
	      rates = new double[arrayRates.size()];
	      for (int i = 0; i < rates.length; ++i)
	      {
	         rates[i] = Double.parseDouble(arrayRates.get(i));
	      }
 
	      inputfile.close();
	    }
	    catch(Exception ec)
	    {
	      JOptionPane.showMessageDialog(null,
	      "Could not find the file specified", "Error Message",
	      JOptionPane.ERROR_MESSAGE);
	    }
	  }
 
	//Verifies input for positive number and returns payment amount
	public void actionPerformed(ActionEvent event) {
		if (event.getSource() == button7)
		{
			years = 7;
			for (int i = 0; i < rates.length; ++i)
			{
				interest = rates[0];
	      	}
		}
		else if (event.getSource() == button15)
		{
			years = 15;
			for (int i = 0; i < rates.length; ++i)
			{
				interest = rates[1];
	      	}
		}
		else if (event.getSource() == button30)
		{
			years = 30;
			for (int i = 0; i < rates.length; ++i)
			{
				interest = rates[2];
	      	}
		}
			intRateText.setText(Double.toString(interest));
			termText.setText(Integer.toString(years));
	    	if (event.getSource() == calculateButton)
	   	{
			try
			{
				displayArea.setText(null);
				String principalTest = principalText.getText();
				principle = Double.parseDouble(principalTest);
			if (principle < 1)
			{
				throw new OutOfRangeException();
			}
			}
			catch (NumberFormatException e)
			{
				principalText.setText("Invalid Amount");
				JOptionPane.showMessageDialog(null, "Enter Positive Numbers Only ", "INVALD ENTRY", JOptionPane.ERROR_MESSAGE);
				return;
			}
			catch (OutOfRangeException e)
			{
				principalText.setText("Invalid Amount");
				JOptionPane.showMessageDialog(null, "Enter Positive Numbers Only ", "INVALD ENTRY", JOptionPane.ERROR_MESSAGE);
				return;
			}
				setResultValue();
	        }
	        //clears fields
		    if (event.getSource() == clearButton)
		    {
	        	principalText.setText("");
	        	termText.setText("");
	        	intRateText.setText("");
	        	paymentText.setText("");
	        	displayArea.setText(null);
	        }
	        if (event.getSource() == graphButton)
	        {
				JFrame f = new JFrame("Chart");
				f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
				f.getContentPane().add(new ChartPanel(values, names, "Principle/Interest"));
				f.setSize(400, 300);
				f.setLocation(300,300);
				f.setVisible(true);
				double principleP = 0.0;
				double interestP = 0.0;
				double[] values = new double[2];
				String[] names = new String[2];
 
				values[0] = principleP;
				names[0] = "Principle";
 
				values[1] = interestP;
				names[1] = "Interest";
				System.out.println(interestP);
				f.getContentPane().add(new ChartPanel(values, names, "Principle/Interest"));
    		}
			if (event.getSource() == exitButton)
			{
				System.exit(0);
			}
		}
 
	//Calculates mortgage payment, creates and displays amortization schedule
	public void setResultValue()
	 	{
	   		double amount = Double.parseDouble(principalText.getText());
	   		double term = Double.parseDouble(termText.getText());
	   		double rate = Double.parseDouble(intRateText.getText()) / 100.;
	   		double result = (amount * ( rate/12))/(1-( Math.pow (1/( 1 +(rate/12)), (term*12))));
		    paymentText.setText("" + dollarAmount.format(result));
 
		    double intPaid = 0;
		    double principalPaid = 0;
		    double balance = amount;
		    double monthlyRate = rate / 12;
		    double months = term * 12;
 
 
		    int payment = 1;
 
		    for (int y = 1; y <= term; y++)
		    {
				displayArea.append("");
 
			// Loop to to calculate and display the payment schedule
			for (int m = 0; m < 12; m++)
			{ /* start inner loop */
				intPaid = balance * monthlyRate;
				principalPaid = result - intPaid;
				balance = balance - principalPaid;
 
				displayArea.append("Month " + payment + "\t" + "   " +"   "
				+ dollarAmount.format(balance) + "\t" +"              "
				+ dollarAmount.format(intPaid) + "\n");
				payment++;
	    		displayArea.setCaretPosition(0);
 
	    		intTotal += intPaid;
				priTotal += principalPaid;
				payTotal += result;
 
				interestP = (intTotal)/(payTotal) * 100;
				principalP = (priTotal)/(payTotal) * 100;
						}
 
					}
			System.out.println(intTotal);//temporary to check results of total (will delete)
			System.out.println(priTotal);
				}
 
			}
 
 
//class to extend Exception to validate numbers for negative and 0 input
class OutOfRangeException extends Exception //Burd, B. (2007). Java for Dummies. Indianapolis, IN: Wiley Publishing, Inc..
{
}
 
class ChartPanel extends JPanel {
 
  private double[] values;
  private String[] names;
  private String title;
 
 
 
  public ChartPanel(double[] v, String[] n, String t)
  {
    names = n;
    values = v;
    title = t;
  }
 
  public void paintComponent(Graphics g)
  {
    super.paintComponent(g);
    if (values == null || values.length == 0)
      return;
    double minValue = 0;
    double maxValue = 0;
    for (int i = 0; i < values.length; i++) {
      if (minValue > values[i])
        minValue = values[i];
      if (maxValue < values[i])
        maxValue = values[i];
  }
 
    Dimension d = getSize();
    int clientWidth = d.width;
    int clientHeight = d.height;
    int barWidth = clientWidth / values.length;
 
    Font titleFont = new Font("SansSerif", Font.BOLD, 20);
    FontMetrics titleFontMetrics = g.getFontMetrics(titleFont);
    Font labelFont = new Font("SansSerif", Font.PLAIN, 10);
    FontMetrics labelFontMetrics = g.getFontMetrics(labelFont);
 
    int titleWidth = titleFontMetrics.stringWidth(title);
    int y = titleFontMetrics.getAscent();
    int x = (clientWidth - titleWidth) / 2;
    g.setFont(titleFont);
    g.drawString(title, x, y);
 
    int top = titleFontMetrics.getHeight();
    int bottom = labelFontMetrics.getHeight();
    if (maxValue == minValue)
      return;
    double scale = (clientHeight - top - bottom) / (maxValue - minValue);
    y = clientHeight - labelFontMetrics.getDescent();
    g.setFont(labelFont);
 
    for (int i = 0; i < values.length; i++) {
      int valueX = i * barWidth + 1;
      int valueY = top;
      int height = (int) (values[i] * scale);
      if (values[i] >= 0)
        valueY += (int) ((maxValue - values[i]) * scale);
      else {
        valueY += (int) (maxValue * scale);
        height = -height;
      }
 
      g.setColor(Color.lightGray);
      g.fillRect(valueX, valueY, barWidth - 2, height);
      g.setColor(Color.black);
      g.drawRect(valueX, valueY, barWidth - 2, height);
      int labelWidth = labelFontMetrics.stringWidth(names[i]);
      x = i * barWidth + (barWidth - labelWidth) / 2;
      g.drawString(names[i], x, y);
    }
  }
}

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
392:
393:
394:
395:
396:
397:
398:
399:
400:
401:
402:
403:
404:
405:
406:
407:
408:
409:
410:
411:
412:
413:
414:
415:
416:
417:
418:
419:
420:
421:
422:
423:
424:
425:
426:
427:
428:
429:
430:
431:
432:
433:
434:
435:
436:
437:
438:
439:
440:
441:
442:
443:
444:
445:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-08-22 at 19:11:14ID24674189
Tags

Java

Topic

New to Java Programming

Participating Experts
2
Points
500
Comments
6

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. sending a variable to a function in a class
    I have a variable which is stored in a cookie for this example. I have a main php page which includes two other pages of classes. my problem is that I want to use a variable value retreived from the cookie in a function which is in a 'nested class'..... I can't get access...
  2. class variables
    I've written the following very basic class but it didn't work so I amended it to return a class variable value and I found that the values of the class variables are not being retained. <?php class Debug { // class variables var $debug_on; var $file; // class constr...
  3. EMERGENCY>>>>STUPID MISTAKE!!!!
    This is a one horse shop, 2 servers, both domain controllers. Named: mail and company1 (name changed to protect the innocent) By Mistake, I built a new desktop and without thinking, wanting to use something generic, chose the name of one of the domain controllers. I reali...
  4. log, time spent in sleep mode
    Ok. I have a program that collects idle data once per minute and output once per hour. A '0' means that there was no user keyboard or mouse activity in the last minute, a '1' means that activity was detected in the last minute. sample output looks like this.. 100001011100000...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: a_bPosted on 2009-08-22 at 21:12:48ID: 25161330

Sharing varibales b/w classes -

class A
{
     int b;
     int c;
     .......
}
class B
{
    int foo(int b, int c)
   {
   }
}

In the main method -
A a = new A();
a.setB(x);
b.setC(y);
B b = new B();
b.foo(a.getB(), b.getC());

Is this what you need?


 

by: Kelela8Posted on 2009-08-22 at 21:32:53ID: 25161363

I don't think so.

my principleP and interestP do not seem to be used outside of the method.
If I code numbers into my graph for the principleP and interestP the graph displays fine.
But if I try to use principleP = 0.0; and interestP = 0.0;
then I get nothing.

if (event.getSource() == graphButton)
   {
	JFrame f = new JFrame("Chart");
	f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	f.getContentPane().add(new ChartPanel(values, names, "Principle/Interest"));
	f.setSize(400, 300);
	f.setLocation(300,300);
	f.setVisible(true);
	double principleP = 200000.00;
	double interestP = 40222.00;
	double[] values = new double[2];
	String[] names = new String[2];
 
	values[0] = principleP;
	names[0] = "Principle";
 
	values[1] = interestP;
	names[1] = "Interest";
	System.out.println(interestP);
	f.getContentPane().add(new ChartPanel(values, names, "Principle/Interest"));
    	}

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen in new window

 

by: a_bPosted on 2009-08-22 at 21:39:59ID: 25161374

double principleP = 200000.00;
      double interestP = 40222.00;
      double[] values = new double[2];
      String[] names = new String[2];
 
      values[0] = principleP;
      names[0] = "Principle";
 
      values[1] = interestP;
      names[1] = "Interest";

These varibles are scoped within the block, ie, the block in which they are declared. To use them outside you need to declare them outside( maybe as member variables of the class).

 

by: Kelela8Posted on 2009-08-22 at 21:43:45ID: 25161379

Thank you so much for your patience! I will  work on changing my variable :)

I have to go to bed now. My head and neck are giving new meaning to killing me from this ALL day.

I can't type for backspacing. I will work on this in the morning.

Again Thank you! And I will try your advice in the morning.

 

by: stmani2005Posted on 2009-08-25 at 10:01:08ID: 25179638

Global Variable Concept

http://www.glenmccl.com/tip_002.htm

 

by: stmani2005Posted on 2009-08-31 at 01:54:12ID: 25221331

Could you Give me a reason for B grade

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...