This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi. This question is really bugging me. Here goes: 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 Given answer: c,e What I don't understand is that why can't I add a window into a container. According to the Java spec., I quote, "A window must have either a frame, dialog, or another window defined as its owner when it's constructed." Doesn't this mean that it can be added to another container, say another window or frame? Is there a particular component which absolutely cannot be added to a container? Please help.
Hi Gaia, You might be getting confused with terminology here. Just because something is created with a parent doesn't mean that it is inside of it. The container methods are for adding components into the container. For example, a button cannot exist outside of its container, but a dialog sure can! Constructing a window using a window parent is not the same thing as added a window into another window. The same thing goes for creating a window using a frame parent. Regards, Manfred.
Joined: Aug 01, 2001
Thanks for your help. Yeah, I was confused with the terminology... Does this mean that I can add a window into a container (for example another window or frame)? Is there a particular component(a top-level container) which absolutely cannot be added to a container? What do you think the answer to that question should be? Do you agree with the answer? I think the answer should only be e. Thanks again for your help.