File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes When component class add method will throws an IllegalArguemnt Exception? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "When component class add method will throws an IllegalArguemnt Exception?" Watch "When component class add method will throws an IllegalArguemnt Exception?" New topic
Author

When component class add method will throws an IllegalArguemnt Exception?

sun ram
Ranch Hand

Joined: Dec 18, 2001
Posts: 61
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


SCSecA,SCNA,SCSA,SCWCD,SCJP
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Answer:c,e
If you have a quick look at the source of java.awt.Container you'll see that. I admit that it could be mentioned somewhere in the API...
[ February 07, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Valentin,
I'm pretty sure you just made a simple typo above, because the answers are c & e, NOT c & d as you wrote.
It's perfectly legal to add a textarea to a container, but it's an error to try to add the container's parent to the container.


Rob
SCJP 1.4
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Thanks Rob,
Damn it, typo again
I confirm answers are c and e
I've edited my previous post
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thanks Val for reminder:
I ran and edited my code, below I add a Window and a Frame to a subclass object of Frame. The strange thing is the second add gives the same
error message: why a Frame is considered a Window here? Sure, Frame is a subclass of Window. Any insights?
import java.awt.*;
public class container1 extends Frame
{
public container1() {super();}
public static void main(String[] args)
{
container1 cn=new container1();
Frame f=new Frame();
Window wd=new Window(f);

//IllegalArgumentException:
//adding window to a container
cn.add(wd);
//IllegalArgumentException:
//adding window to a container
cn.add(f);
}
}
victor
Originally posted by Rob Ross:
Valentin,
I'm pretty sure you just made a simple typo above, because the answers are c & e, NOT c & d as you wrote.
It's perfectly legal to add a textarea to a container, but it's an error to try to add the container's parent to the container.

[ February 07, 2002: Message edited by: victor gu ]
[ February 07, 2002: Message edited by: victor gu ]
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
try this one:

HIH
[ February 07, 2002: Message edited by: Valentin Crettaz ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: When component class add method will throws an IllegalArguemnt Exception?