O'Reilly logo

Developing Java Beans by Robert Englander

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The BeansBook.SimulatorBeanInfo Classes

This section contains the code for the BeanInfo classes for the BeansBook.Simulator package. All of the concepts and techniques used by these classes have been discussed in this chapter. Instead of boring you by describing the code, I’m just including it here for you to look at if you wish.

The BeansBook.Simulator.TemperatureBeanInfo Class

package BeansBook.Simulator; import java.beans.*; import java.lang.reflect.*; public class TemperatureBeanInfo extends SimpleBeanInfo { // return a bean descriptor for the Temperature object public BeanDescriptor getBeanDescriptor() { // create an instance of BeanDescriptor BeanDescriptor bd = new BeanDescriptor(Temperature.class); // set the display name bd.setDisplayName("Temperature Source"); // return the descriptor return bd; } // return the property descriptors public PropertyDescriptor[] getPropertyDescriptors() { try { // get the Temperature class Class c = Temperature.class; // get the get method for the Temperature property Method getter = c.getMethod("returnTemperature", null); // create the parameters array for the set method of the // Temperature property Class[] params = { java.lang.Double.TYPE }; // get the set method Method setter = c.getMethod("assignTemperature", params); // create a property descriptor for the Temperature property PropertyDescriptor pd = new PropertyDescriptor("Temperature", getter, setter); // the Temperature property is bound pd.setBound(true); // the Temperature property ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required