To use menus in your application you need to add instances of all three classes, one
MenuBar
with one or more Menu
s, each with several MenuItem
s.
The java.awt.MenuComponent
class is the ultimate superclass
of all these classes. MenuComponent
extends java.lang.Object
. Thus menus,
menu bars, and menu items are not components and cannot be added to containers
in the usual fashion.
java.lang.Object
|
+---java.awt.MenuComponent
|
+---java.awt.MenuBar
|
+---java.awt.MenuItem
|
+---java.awt.Menu
|
+---java.awt.PopupMenu
Both MenuBar
and MenuItem
extend MenuComponent
. Menu
extends MenuItem
. (This sounds a little strange, but if you think about it a menu is an item in
a menu bar.) Furthermore, MenuBar
implements the java.awt.MenuContainer
interface.