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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access