Saturday, 15 September 2012

swing - What is the method invoked when I use this method call in Java? -



swing - What is the method invoked when I use this method call in Java? -

import javax.swing.*; class foo{ public static void main(string args[]){ jframe f=new jframe(); f.add("north",new jbutton()); //line 1 f.add(new jbutton(),"north"); //line 2 f.setvisible(true); } }

the swing api states jframe class contains 5 methods name add, inherited java.awt.container , add together method inherited java.awt.component.

**their signatures follows:** *inherited java.awt.container* add(component) add(component,int) add(component,object) add(component,object,int) add(string,component) *inherited java.awt.component* add(java.awt.popupmenu)

i expected in api there 2 overloaded method signatures add(component,string) , add(string,component). seeing not case assume line 1 invokes add(string,component) , line 2 invokes add(component,object).

also, can give me explanation how invoked methods implemented. tried figure out looking @ source of api method invocation chains labyrinth , utilize guidance of who's been there before.

eventaully, phone call container#addimpl(component, object, int), expect add(popupmenu)

add(component) calls addimpl(comp, null, -1) add(string, component) calls addimpl(comp, name, -1) add(component, int) calls addimpl(comp, null, index) add(component, object) calls addimpl(comp, constraints, -1) add(component, object, int) calls addimpl(comp, constraints, index)

addimpl lot of work...

it makes sure;

that component been added self that component isn't type window (as can't add together windows components) that component's graphics configuration same that component isn't contained within existing container, , removes if is that component been added within valid index range (if index > -1)

it then...

adds component list of components been managed container calls component's addnotify method (if container realized on screen) notifies layout manager of newly added component notifies listeners container event (componentadded) , hierarchy event (hierarchychanged)

extra

the "add" methods decorators. supply number of entry methods filter downwards single method, intended create live of developer simpler based on context of there work.

java swing jframe

No comments:

Post a Comment