Use the final CentralPerk.java,
CentralPerkBeanInfo.java,
PerkEvent.java,
and PerkListener.java files from the
Packaging Central Perk with Marcel
exercise, which we have here, and place them in their own package.
(or just leave them where they are and work from there).
Since we are going to be working in our own 'BeanBox' like application, we
need to provide our own means of updating a Bean's properties. One way is to
create a Customizer
for the Bean. Another is to create a Property
Sheet. For this task, create a Customizer
for the Font
and Message properties. Creating a Property Sheet is left as an exercise
for the student (and not necessary for this exercise).
Update the BeanInfo
so that it knows about the
Customizer
Compile everything in the package. There is no need to create a .jar
file, unless you want to.
Now the fun begins. In the Top40
framework, there are four methods
to be completed. The first is newBean
which creates a new Bean.
Have the newBean
method instantiate the CentralPerk
Bean you've been working on. Add it into the center quadrant of the screen,
call the checkCustomize
method provided (this turns a menu
choice on if a Customizer is available) and save a reference to the Bean
in the theComp
variable.
Next is our save method, saveBean
. Through Serialization, save the
Bean to the file CentralPerk.ser. Remember that we saved a reference
to it in theComp
.
And our read method, loadBean
is next. Loading is just like the
newBean
method, except the object is read from an
ObjectInputStream
instead of being instantiated. Don't forget
to add it to the center quadrant, call checkCustomize
, and
save a reference in theComp
.
Finally, when the user selects the Customize Bean
menu item, we
need to display the Bean's customizer. Through the Introspector
,
you get the BeanInfo
, then the BeanDescriptor
,
then the CustomizerClass
, and create an instance of it.
After creating an instance of it, you need to tell it which
CentralPerk
to customize, via its setObject
method. Now you can display it. Since the Customizer
is a
Panel
, we need to wrap it up in
a Dialog
with a Done
button. Since the
Customizer
handles all its own actions,
you only need to handle the button selection to hide the dialog.
Compile Top40
.
Run the program. The first thing you have to do is load the
CentralPerk
Bean. Once loaded, you can save it, open it,
customize things, and quit. After quitting and restarting, you can reopen
the last saved Bean.
The task numbers above are linked to the
step-by-step