Results 1 to 4 of 4
- 08-25-2011, 04:12 PM #1
Conceptual question: access to an object created in another class
I hope you will forgive me for not posting the code since I think this is a conceptual problem. In my main class I have created an object, which has its own variables of a particular value. Then in another class which handles the GUI of my program I wish to refer to this object and its values. I do not know how to do this. I can't create a new object of the same class since this would not share the same values as the object in the main class. Can anyone set my thinking straight?
- 08-25-2011, 04:23 PM #2
You're going to have to pass the callee Object to the caller Object, either via a set method or by passing it into the constructor.
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 08-25-2011, 04:30 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Pass the first object into the second, either in the constructor or a set method.
Something along those lines.Java Code:public class Main { .... main(String[] args) { SomeClass someObject = new SomeClass(); MyGUI myGUI = new MyGUI(someObject); .... } } ... public class MyGUI { SomeClass someObject; public MyGUI(SomeClass someObject) { this.someObject = someObject; } }
- 08-25-2011, 04:46 PM #4
Similar Threads
-
How do you access a defined object from another class?!?!
By Baldie in forum AWT / SwingReplies: 2Last Post: 06-16-2011, 09:39 AM -
Class object passed into println(obj) question
By silverglade in forum New To JavaReplies: 4Last Post: 05-15-2011, 11:27 PM -
Drawing an object in my canvas class, the object is created in a separate class
By Hornfreak in forum AWT / SwingReplies: 3Last Post: 05-02-2011, 04:37 AM -
How to assign unique id to each object created from same class
By srisar in forum New To JavaReplies: 2Last Post: 02-18-2010, 05:26 PM -
how to pass an arraylist from an object back to the parent object that it was created
By george_a in forum New To JavaReplies: 1Last Post: 03-04-2009, 06:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks