• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When component class add method will throws an IllegalArguemnt Exception?

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob,
Damn it, typo again
I confirm answers are c and e
I've edited my previous post
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this one:

HIH
[ February 07, 2002: Message edited by: Valentin Crettaz ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic