This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Getting an array out from an instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting an array out from an instance" Watch "Getting an array out from an instance" New topic
Author

Getting an array out from an instance

Kari Nordmann
Ranch Hand

Joined: Feb 12, 2007
Posts: 38
Im working on a small program of my own interest, where I have one class to deal with all graphics, and one class to deal with everything under the GUI.
- The Control class will make 24 objects of Resource. Each object is saved in an array in the Control class.
- The Control class instanciates the GUI class.
- I want to create one jlabel in the GUI class for every object of class Resource.

So I was thinking the best way to make the labels would be to get each Resource object from the array in the Control Class, and then get the names from the ojects.
But then there's the problem: I dont know how to reach the array without instanciating the Control class. And I can't instanciate it, since that would only mean referring to a new Control class and start at scratch...

So, what should I really do to get the array over from Control to View?
[ May 03, 2008: Message edited by: Kari Nordmann ]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

Kari,
The most straightforward way I can think of is to have a separate class containing all the arrays (ResourceData class maybe.) The Control class can still instantiate everything and pass a reference to the ResourceData to the GUI class.

It is possible to pass the Control class to the GUI class directly (by passing the this object). However, this isn't clear design and should be avoided if possible.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting an array out from an instance
 
Similar Threads
Simple answer--unknown question
Welcome Kathy Sierra and Bert Bates to our Book Promotion of the Week
Shared resource synchronization
How do I know?? (methods vs classes vs main)
Reacting to events outside of the class in which an event occurs