File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Container

 
Supree
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Supree
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about applet?Applet is not a window. Is it possible to add appllet in a container.
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3226
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic