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

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