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
Printable View
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
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
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..
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)