• 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

Using object in different class

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there, another concept Im struggling with...







I have methods defined in a Mesh class. I want to use these methods as the scrollbar is adjusted - (i.e. within the ScrollbarListener class - geo.someMethod() ) However geo is inialised in the MeshTesterGLSpace class. How can I use this object (geo) in the ScrollbarListener class?
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ScrollListener, being an inner class of MeshTester, can invoke any method on its enclosing object, even private methods:

Therefore, if you can write a MeshTester method that does what you want, then you can call it from ScrollListener.
 
Jackie Davis
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm...

I see what you are saying. But I have a 'Mesh' object intialised in the MeshTesterGLSpace class called 'geo'.

I have a seperate Mesh class with methods.

I would like to use the object geo in ScrollListener (i.e geo.getVertices(); ). But because the Mesh object 'geo' has not been initalised in the MeshTester class I cannot use it here.

Hope I've explained this ok.

How do I get around it?

Thanks
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You metioned that field geo has not been initialised. Why not? It's hard to send a message to an object that doesn't exist
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This may help:

Have a MeshTesterGLSpace instance (myMeshTesterGLSpace) in the MeshTester Class.

Call the method that initializes the geo object:
myMeshTesterGLSpace.initMesh()

Then you can use the geo object as

myMeshTesterGLSpace.geo

-Vinayak
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, what's the relationship between MeshTester and MeshTesterGLSpace?
1. Does one have an instance of the other as a field?
2. Is one passed the other in some method?
3. Is one created locally in the method of the other?
There's many ways to get objects to send messages to each other.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic