Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

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

  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.

[ This page was updated: 10-Nov-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.