aspose file tools*
The moose likes Java in General and the fly likes Accessing component from main class.... Help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Accessing component from main class.... Help!" Watch "Accessing component from main class.... Help!" New topic
Author

Accessing component from main class.... Help!

Naf Rash
Ranch Hand

Joined: Feb 19, 2004
Posts: 85
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!!
Eddie Vanda
Ranch Hand

Joined: Mar 18, 2003
Posts: 281
There are a million ways and this is just one of them:


The nice thing about Standards is that there are so many to choose from!
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing component from main class.... Help!