A FrameWithMenuBar Class

Applications containing a menubar typically do the following things:

  1. Create a menubar

  2. Add menus to the menubar

  3. Set the frame's menubar

In good object-oriented fashion, we will encapsulate these tasks in a base class illustrated in Example 17-4. You can extend this class whenever you need a frame with a menubar.

OO TIP

Encapsulate Common Functionality in Base Classes

Encapsulating common functionality in a base class is one of the tenets of object-oriented development; it increases reuse and reduces reimplementation of reimplementing similar functionality in more than one class. Often, such code is not identified until two or more classes have reimplemented the same functionality. In such cases, it is well worth your while ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.