• 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

Accessing component from main class.... Help!

 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic