CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    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


  2. #2
    Join Date
    Jan 2000
    Location
    CA, USA
    Posts
    305

    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




  3. #3
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    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..


  4. #4
    Join Date
    Dec 1999
    Posts
    23

    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
  •  





Click Here to Expand Forum to Full Width

Featured