Sun Java Solaris Communities My SDN Account Join SDN
 
Tutorials & Code Camps

JavaBeans Short Course

 
Training Index

Short Course

[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:


  1. 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.

  2. 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.

  3. 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.

  4. Next, we need to create a PerkListener and give it a method for us to call when the PerkEvent happens. Lets call it startedPerking.

  5. 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.

  6. Finally, we need to check if everything is Serializable. Flag anything that isn't as transient

  7. 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.

  8. 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.