|
-
May 8th, 2000, 09:59 AM
#1
Don't understand this line ?
Would you like please explain to me what does this line mean :
for(theFrame = getParent(); !(theFrame instanceof Frame) && theFrame != null; theFrame = ((Component)theFrame).getParent());
Thanks
-
May 8th, 2000, 10:13 AM
#2
Re: Don't understand this line ?
Hi,
for(theFrame = getParent(); !(theFrame instanceof Frame) && theFrame != null; theFrame = ((Component)theFrame).getParent());
The loop starts from the parent of your current
frame and continues till it reaches the top
of your hierarchy(tree).
I am not sure about the condition:
!(theFrame instanceof Frame).
To me it probably would have made sense if
the not ! operator wasn't there. In that case,
it would be from your frame's parent to the
Frame Class.
Kannan
-
May 8th, 2000, 11:14 AM
#3
Re: Don't understand this line ?
The code which you post trying to get the parent "Frame" from the current component.
for loop structure ..
for( initializer ; condition ; increment ){}
Ex : for( int i = 0 ; i < 10 ; i++ ){}
In your code
Initializer : theFrame = getParent() ( like int i = 0 )
gettting the parent component of the current component.
condition : !( theFrame instanceof Frame ) ( like i < 10 )
checks whether the current component is Frame. If it is , break the loop.
Increment : theFrame = ((Component)theFrame).getParent() ( like i++ )
get the parent of the "theFrame" Component.
More readable code :
public Frame getParentFrame( Component c ){
// c should not be null and should not be Frame
// If it's Frame , break the loop and return it.
while( ( c != null ) && !( c instanceof Frame ){
c = c.getParent();
}
return ( Frame ) c;
}
Poochi..
-
May 10th, 2000, 01:43 AM
#4
Re: Don't understand this line ?
It simply tries to find the Frame that the component theFrame has been added to.
getParent() returns the Container of theFrame.
Frame (Container)
^
Panel (Container)
^
Component (theFrame)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|