| | |
problems with referring to class variables
![]() |
•
•
Join Date: Nov 2004
Posts: 15
Reputation:
Solved Threads: 0
I'm having a problem with a GUI i'm building. I have a separate class called Calculations.class which does nothing except hold certain variables and do calculations with them. One of my classes requires a user to enter numerical data, and when a button is pressed, these variables are set in calculations.class, which is fine. However, when I try to access these variables in Calculations.class from another class, it seems like all the variables are set back to zero, and do not have the values set by the user originally. Any help would be fantastic!!
•
•
Join Date: Nov 2004
Posts: 1
Reputation:
Solved Threads: 0
Your Problem is Scope of variables. Please use static variable which are class variables and retain there values. If U want to use instance variables then U should be careful about the Object which get created when user clicks the button. U can not refer the same object in different file. At that time it creates new instance of that class and hence valued U get will be default. If U want to use in different Independent class then U have to pass these variables to new class thorogh constructor.
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: Java DSW algorithm Coding
- Next Thread: Setting preset for a JMF Player
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth bold business c++ chat class clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse educational error file formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide ideas image infinite ingres integer intersect invokingapacheantprogrammatically j2me java javaexcel javaprojects jni jpanel jtextarea julia linux list map method methods mobile mysql netbeans newbie openjavafx parameter php problem program programming project recursion repositories scanner scrollbar sell server set sms sort sorting sql sqlserver state storm string sun superclass swing swt threads tree websites windows






