The Container methods add(Component comp) and add(String name, Component comp) will throw an IllegalArgumentException if "comp" is a: a) button b) list c) window d) textarea e) container that contains this container The answer is c),e). why the window can not add to the container? and by the way, the container aslo can not add to the container?
A window is a top level class and cannot be incorporated into other components. So you cannot add window to a container. You can add one container to other in general. However the question is adding a container to a container which has the former container. Getting confused? Suppose you have container A which has several buttons, textfields, labels etc. You can add other containers (say B, C etc.) to A. Suppose A itself is added to another container Z. Then you cannot add Z to A.
That�s an interesting question! I remember reading Tony Alicea explanation where he said that although add method, defined in Container class has signature add(Component comp), attempt to add a window will cause IllegalArgumentException. I looked at add() method code. All overloaded versions of it merely call addImpl method, whose comments said:
/* Check for correct arguments: index in bounds, * comp cannot be one of this container's parents, * and comp cannot be a window. */
here is part of addImpl code:
Interesting, that java API� description for add methods never mentioned that Window cannot be added to a container. I believe that you can add Panel or Applet to a container.
[This message has been edited by Mapraputa Is (edited September 20, 2000).]