Author Topic:   MenuBar can be added to applets?
Anju Rao
ranch hand
posted March 08, 2000 01:49 PM         
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,

maha anna
bartender
posted March 08, 2000 03:37 PM             

java.lang.Object
|
+--java.awt.MenuComponent
|
+--java.awt.MenuItem
|
+--java.awt.Menu
|
+--java.awt.PopupMenu

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
posted March 08, 2000 03:37 PM         
Maha Anna or others,

What do u think of this? It is definitely wrong, i think.

Mahen
greenhorn
posted March 09, 2000 06:27 AM             
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.......

|