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!!
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 ]
subject: Accessing component from main class.... Help!