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]



Skeleton Code

Using BeanInfo and reflection help Juan Valdez inspect his beans. This exercise shows you how to get access to bean information without directly calling methods or inspecting properties. Instead, you ask a Bean's BeanInfo what it knows about and use this to access a Bean's properties and determine what kind of event listeners you can register.

The task of this exercise is to complete the inspect method of the Valdez skeleton to list the names and values of all properties and names and listener types for all event listeners of the Bean.

Perform the following tasks:


  1. The Introspector is used to get the BeanInfo of a Bean. Since it works with an instance of Class, you need to get the Class of the bean passed to our inspect method.

  2. Now that you have a Class, use the Introspector to get at its BeanInfo.

  3. From the BeanInfo, get the list of properties for the Bean. You will end up with an array of PropertyDescriptors.

  4. For each element of the PropertyDescriptor array, display the name, datatype, and current value.

  5. From the BeanInfo, get the list of event sets for the Bean. You will end up with an array of EventSetDescriptors.

  6. For each element of the EventSetDescriptor array, display the name and listener type.

  7. Use the Burro frame provided in Burro.java to test out the inspect method of Valdez. Burro creates a Frame with a bunch of AWT Beans on it. When you double-click on a List element, select a Checkbox, or press return in the TextField, Juan goes to work and inspects the Bean selected. The results of the inspection are shown in the TextArea in the middle.

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.