Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Accessing component from main class.... Help!

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose I have three classes- Class 1, class 2 and class 3. Class 1 is the main class. Class 1 creates an object of class 2. Class 2 creates an object of class 3. Class 3 wishes to have a fileChooser dialog box disaplyed which requires the parent component to be called (ie, the frame in which the dialogue should appear.). However, this component is in class 1. How do I tell it to use the frame and set sizes from the main class (Class 1)?
Please Please try to help - I'm really stuck!!
 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a million ways and this is just one of them:
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't want to keep passing around the parent frame everywhere, you can do something like this:

You put this method in Class3--or wherever you need it--and it returns the parent frame. Basically it keeps calling "getParent()" until it gets to the outermost container, which is generally a Frame (or JFrame), and returns that.
This assumes that "Class3" extends JPanel or some other UI container class where the call to "getParent()" is defined. If not, replace the first line with: Component frame = someComponent.getParent(); where "someComponent" is a UI component in the interface.
[ March 30, 2004: Message edited by: Wayne L Johnson ]
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic