aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Container 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 "Container" Watch "Container" New topic
Author

Container

Supree
Greenhorn

Joined: Feb 25, 2000
Posts: 27
What can't be added to container?
a.Componet
b.Container
c.panel
d.Applet
e.Frame
f.Container
g.Menu
f.Menu component
I am not clear about this, Could anyone answer pl?
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
What don't you understand in particular? It would not serve any purpose just to give the answer. There is something to understand about the AWT Container and MenuComponent hierarchy/relationship and the concept of top-level windows... What does your text on Java say about that?
You may be able to take a hint from the AWT Components hierarchy that I copied to my Java page. It's item (2) here


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Supree
Greenhorn

Joined: Feb 25, 2000
Posts: 27
I know the AWT component hierarchy.
My doubt is whether all sub classes of container can be added to a container or Is there any criteria of what can be added to a container.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
The criteria is that <CODE>Window</CODE>s cannot be added to containers. <CODE>Frame</CODE>, <CODE>Dialog</CODE> and <CODE>FileDialog</CODE> are <CODE>Window</CODE>s.
Neither can <CODE>MenuComponent</CODE>s
Supree
Greenhorn

Joined: Feb 25, 2000
Posts: 27
What about applet?Applet is not a window. Is it possible to add appllet in a container.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
An Applet is a Panel. So wherever you can add a panel, you can add an applet. Why would you want to do it is another matter. Applets are special purpose Panels for Web pages.
The following compiles and executes:
<PRE> public static void main (String[] args) {
Applet ap = new Applet();
Window w = new Window(new Frame() );
w.add(ap);
}
</PRE>
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
tony,
why can't Windows be added to Containers? the add method of Container takes any Component as argument and Window inherits from Component.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
Yes but it is still illegal. You'll get a runtime IllegalArgumentException if you try to add a Window to a Container.
deepti_1978
Greenhorn

Joined: Feb 24, 2000
Posts: 2
can anybody please explain
if we can't add a menucomponent to a container then how it is possible to add a menubar to a frame.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
(1) We can't add a MenuComponent to a Container because the java.awt.Component)" rel="nofollow">Container.add() takes Component objects as arguments not MenuComponent.
(2) We can "add" a MenuComponent (In the form of a MenuBar) to a Frame because the Frame class allows it via the java.awt.MenuBar)" rel="nofollow">setMenuBar() method.
In my SCPJ2 page I reproduce Sun's inheritance hierarchies for all the AWT component classes. You can get to that page from my main Java page, item (8).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Container