O'Reilly logo

Graphic Java™ 1.2, Volume I: AWT, Third Edition by David M. Geary

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required