The Menu Classes

Figure 17-1 shows the relationships between the AWT's menu classes.

Figure 17-1. AWT Menu Classes Diagram

We will be concerned with four classes when dealing with menus: MenuBar, Menu, MenuItem, and PopupMenu. The first thing to note from the class diagram is that each of these classes extends MenuComponent; a MenuComponent is simply something that can be displayed in a menu. Second, notice that Menu and Menubar both implement MenuContainer, meaning they may both contain instances of MenuComponent. Finally, note that Menu extends MenuItem; this enables the creation of cascading menus, as we shall soon discover.

It is worth repeating ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.