update() will be called by the Observable if someone ever calls the notifyObservers() method. Since the Observable is local to your Observer's constructor, there's no way this will ever happen.
Normally the way these things are used is that you make a subclass of Observable, Observers register with it, and then the subclass calls notifyObservers() on itself when "something happens" -- i.e., when there is an event that it wants the Observers to know about.
Yes, the example is convoluted, but notifyObservers() is indeed called. The real problem is that setChanged() has never been called. The API is not very clear about this, but when notifyObservers() is called, the first thing it does is check whether the object has been "changed" (meaning, has setChanged() been called) and if not, it does nothing. Here's an example that works:
It should also be noted that java.util.Observer and Observable aren't God's gift to OOP. (For example, on either's javadoc page, go to the top and click on the USE link. They aren't used in the rest of the Java API!) There's not a lot of code in Observable, so if you want to code the Observer pattern from scratch or using, say, SwingPropertyChangeSupport, go for it. [ November 22, 2005: Message edited by: Jeff Albrechtsen ]
There is no emoticon for what I am feeling!
author and iconoclast