• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Container

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(1) We can't add a MenuComponent to a Container because the 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 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).
 
Time is mother nature's way of keeping everything from happening at once. And this is a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic