A MenuBar Printer

To illustrate the relationships between menus, menubars, and menu items, we'll present a simple class in Example 17-3 that walks you through all the menus in a menubar and prints information about each item.

Example 17-3. MenuBarPrinter Class Listing
 import java.awt.Menu; import java.awt.MenuItem; import java.awt.MenuBar; public class MenuBarPrinter { static public void print(MenuBar menubar) { int numMenus = menubar.getMenuCount(); Menu nextMenu; MenuItem nextItem; System.out.println(); System.out.println("MenuBar has " + menubar.getMenuCount() + " menus"); System.out.println(); for(int i=0; i < numMenus; ++i) { nextMenu = ...

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.