![]()
(chat, newsreader, calendar)
|
![]() |
|
|
|
Course Notes Table of Contents Exercises | Online Training Index
|
|
Help: From Kiva Han to Central Perk
MageLang Institute
|
|
Help is available for each task, or you can go straight to
the solution source code.
Their method signatures need to be: public void setMovingRate (int rate); public int getMovingRate (); Task 2In 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.The listener list should be private: private PropertyChangeSupport changes = new PropertyChangeSupport (this);The adding and removing of listeners routines should be public:
public void addPropertyChangeListener (
PropertyChangeListener p) {
changes.addPropertyChangeListener (p);
}
public void removePropertyChangeListener (
PropertyChangeListener p) {
changes.removePropertyChangeListener (p);
}
In the set routines, be sure to call changes.firePropertyChange.
Task 3Whenever 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.Bean events need to subclass java.util.EventObject. Remember to create a getMessage method for the message property. Task 4Next, we need to create a PerkListener and give it a method for us to call when the PerkEvent happens. Lets call it startedPerking.Listeners need to implement java.util.EventListener. Its startedPerking routine needs to accept a PerkEvent parameter. Task 5Back 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.
Task 6Finally, we need to check if everything is Serializable. Flag anything that isn't as transientAll the basic data structures and datatypes are Serializable, so you don't have to worry about things like String, Vector, and PropertyChangeSupport. However, Thread is not. Mark Thread as a transient variable. Task 7Because 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.
Task 8Okay, now that we've finished our Bean, we can try it out. Use the CentralPerkTester applet and loader to try it out.There is a label at the top of the applet that listens for the message property to change. Whenever the PerkEvent happens, a message is printed to the console.
|
|
Copyright © 1997 MageLang Institute. All Rights Reserved May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved |