A File Menu

Let's start off our discussion of menus residing in menubars with a simple example that creates the file menu in Figure 17-2.

Figure 17-2. A File Menu

Most applications that provide a menubar have a file menu as the leftmost menu in their menubar, and most provide menu items similar to those we have added to our example. Implementing such a menu is straightforward, as illustrated in Example 17-1.

Example 17-1. FileMenuTest Class Listing
 import java.awt.*; import java.awt.event.*; public class FileMenuTest extends Frame { private MenuBar mbar; private MenuItem newItem, openItem, saveAsItem, saveItem, quitItem; private MenuItemListener ...

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.