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