P.3. Design Patterns in Packages java.awt and javax.swing

This section introduces those design patterns associated with Java GUI components. It should help you understand better how these components take advantage of design patterns and how developers integrate design patterns with Java GUI applications.

P.3.1. Creational Design Patterns

Now, we continue our treatment of creational design patterns, which provide ways to instantiate objects in a system.

Factory Method

Suppose that we are designing a system that opens an image from a specified file. Several different image formats exist, such as GIF and JPEG. We can use method createImage of class java.awt.Component to create an Image object. For example, to create a JPEG and GIF image in an ...

Get Java™ How to Program, Seventh 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.