• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting an array out from an instance

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic