The message and the moving rate are two properties for CentralPerk (properties like font and
background/foreground color are inherited through Canvas
). There are currently setter/getter
routines for the message property. Add routines for the MovingRate property.
In order to make our properties bound, we need to maintain a PropertyChangeSupport
list
and add/remove listeners to it. Also, the property set
routines need to be modified to
fire property changes to the listeners when the changes happen. Be sure to update both
setMessage
and setMovingRate
.
Whenever a message starts scrolling in from the right, we want to generate a PerkEvent
. In
order for this to happen, we need to define the event, and give it a read-only
message property.
Next, we need to create a PerkListener
and give it a method for us to call when the
PerkEvent
happens. Lets call it startedPerking
.
Back in CentralPerk
, we need to maintain a PerkListener
list and add/remove listeners
to it. Also, when the event happens, we need to notify the listeners.
Finally, we need to check if everything is Serializable
. Flag anything that isn't as
transient
Because of the nature of our transient variable, we need to override the default serialization
reading routine readObject
to initialize the variable. The writing routine writeObject
doesn't have to do anything special, but because of the requirements of serialization is required to be
present. Add a readObject
and writeObject
routine
to CentralPerk
.
Okay, now that we've finished our Bean, we can try it out. Use the
CentralPerkTester applet and
loader
to try it out.
The task numbers above are linked to the
step-by-step