Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information JDC Resources DukeDollars Early Access

Java Cup Logo

JDC Applets
(chat, newsreader, calendar)

Log Out

Online Training
shadowSearchFAQFeedback

Course Notes Table of Contents
Exercises | Online Training Index

Saving Billboards with Casey Kasem
MageLang Institute

[Help | Solution | API Docs | Behavior | Course Notes | Exercises]

Prerequisites

Skeleton Code

This exercise adds a Customizer to the CentralPerk Billboard Bean. Also, you create a testing application with Bean save/restore capabilities.

Perform the following tasks:

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

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

  3. Update the BeanInfo so that it knows about the Customizer

  4. Compile everything in the package. There is no need to create a .jar file, unless you want to.

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

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

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

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

  9. Compile Top40.

  10. 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 help page. Also available is a complete solution to the problem, and expected behavior, to demonstrate it.


Copyright © 1997 MageLang Institute. All Rights Reserved
May-97 Copyright © 1996, 1997 Sun Microsystems Inc. All Rights Reserved