Training Index
Short Course
From Kiva Han to Central Perk
By MageLang Institute
[Tutorial Contents]
[Behavior] [Help]
[API Docs]
[Solution]
Prerequisites
Skeleton Code
In 1994, NBC's Friends started hanging out in Central Perk.
It is meant to represent the upscale coffeehouses of today.
This exercise builds upon the basic KivaHan bean, from the Kaidi
exercise, into the sophisticated CentralPerk bean. Instead of being a non-scrolling billboard like Kaidi,
CentralPerk is a customizable scrolling bean, with perking events and constrained properties. The
skeleton for CentralPerk provides a scrolling billboard, you get to add the parts that make it a Bean.
Perform the following tasks:
- 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 help page. Also available
is a complete solution to the
problem, and expected behavior,
to demonstrate it.
Copyright © 1997 MageLang Institute. All Rights Reserved.
|
|