O'Reilly logo

Design Patterns Java™ Workbook by Steven John Metsker

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 Classic Example: Observer in Swing

The most common case in which clients depend on changing objects occurs in graphical user interfaces. Whenever a user clicks a button or adjusts a slider, many objects in the application may need to react to the change. Java Swing anticipates that you will be interested in knowing when a user changes a Swing component, and the OBSERVER pattern is evident throughout Swing. Swing refers to interested clients as “listeners” and lets you register as many listeners as you like to be notified of a component's events.

Consider a typical Oozinoz application with a Swing GUI, such as the one that Figure 9.1 shows. This application lets a fireworks engineer experiment visually with parameters that determine the relationship ...

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