• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

MenuBar can be added to applets?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I saw a statement in R& H saying that MenuBArs can only be added to Frames.
But in Bill Brogdens' book, the following question.
Which of the following AWT components can have a menu, eithere as a menubar or pop-menu attached to it? Check all correct answers.
a)Frame
b)Window
c)Applet
d)Panel
All are correct because componet class implements MenuContainer interface and all of these classes have Component in their ancestry?
Per Tony Alecia's Hierarchy chart, all menus, menuitems etc inherit from MenuComponent which is extended from Object. Where is this MenuContainer interface coming from?
Thanks in advance,
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<pre>
java.lang.Object
|
+--java.awt.MenuComponent
|
+--java.awt.MenuItem
|
+--java.awt.Menu
|
+--java.awt.PopupMenu
</pre>
In Component class there is a method as follows
add(PopupMenu popup)
Adds the specified popup menu to the component.

A PopupMenu is a special menu which CAN BE ADDED to ANY kind of component. Have you seen in applications if you right-click a popup menu appearing? This PopupMneu is used in situations like that. Since the qstn specifically asked for adding a menu in the form of menubar or a popup-menu all these come into picture. So the answer is correct.
But I do not get the MenuContainer interface part. the add(PopupMenu pop) is not inherrited from this interface.
regds
maha anna

[This message has been edited by maha anna (edited March 08, 2000).]
 
Anju Rao
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maha Anna or others,
What do u think of this? It is definitely wrong, i think.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey anju
see menubars can only be added to Frames
because setMenuBar(menubar)method is only present in frames class
and as the PopupMenu can be added thru class Component as add(PopupMenu) you can add popup menu to all the components in the above question because all are inherited from the component
here what is happening in class Component there is composition(aggregation) wrt PopupMenu class.........(not exact composition but we can say composition) look in the java source code which comes along with jdk1.2...
add() method is overloaded to include the popupmenu capability to components.....inherited from Components.......
hope i am correct.......
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic