JAVA BEANS API
JAVA BEAN API
• The Java Beans functionality is provided by a
set of classes and interfaces in the java.beans
package.
INTERFACES IN JAVA BEAN API
• Table lists the interfaces in java.beans and provides a brief
description of their functionality.
Interface Description
AppletInitializer Methods in this interface are used to initialize Beans that are
also applets.
BeanInfo This interface allows a designer to specify
information about the properties, events, and methods of a
Bean.
Customizer This interface allows a designer to provide a graphical user
interface through which a Bean may be configured.
DesignMode Methods in this interface determine if a Bean is executing in
design mode
ExceptionListener A method in this interface is invoked when an exception
has occurred
INTERFACES IN JAVA BEAN API
PropertyChangeListener A method in this interface is invoked when a bound
property is changed.
PropertyEditor Objects that implement this interface allow designers to
change and display property values
VetoableChangeListener A method in this interface is invoked when
a constrained property is changed.
Visibility Methods in this interface allow a Bean to execute
in environments where a graphical user interface is
not available.
CLASSES IN JAVA BEAN API
• Table lists the some of the classes in java.beans and provides
a brief description of their functionality.
CLASSES DESCRIPTION
BeanDescriptor This class provides information about a Bean. It also allows you
to associate a customizer with a Bean.
EventSetDescriptor Instances of this class describe an event that can be generated
by a Bean.
FeatureDescriptor This is the superclass of the PropertyDescriptor,
EventSetDescriptor, and MethodDescriptor classes.
IndexedPropertyDescriptor Instances of this class describe an indexed property of a Bean.
IntrospectionException An exception of this type is generated if a problem occurs
when analyzing a Bean
CLASSES IN JAVA BEAN API
Introspector This class analyzes a Bean and constructs a
BeanInfo object that describes the component.
MethodDescriptor Instances of this class describe a method of a Bean.
PropertyChangeEvent This event is generated when bound or constrained
properties are changed. It is sent to objects that
registered an interest in these events and
implement either the PropertyChangeListener or
VetoableChangeListener interfaces.
PropertyChangeSupport Beans that support bound properties can use this
class to notify PropertyChangeListener objects.
EXAMPLE PROGRAM FOR JAVABEAN API
package sunw.demo.colors;
import java.awt.*;
import java.beans.*;
public class IntrospectorDemo {
public static void main(String args[]) { try {
Class c = Class.forName("sunw.demo.colors.Colors");
BeanInfo beanInfo = Introspector.getBeanInfo(c);
BeanDescriptor beanDescriptor =
beanInfo.getBeanDescriptor();
EXAMPLE PROGRAM FOR JAVABEAN API
System.out.println("Bean name = " +
beanDescriptor.getName());
System.out.println("Properties:");
PropertyDescriptor propertyDescriptor[] =
beanInfo.getPropertyDescriptors();
for(int i = 0; i < propertyDescriptor.length; i++)
{ System.out.println("\t" +
propertyDescriptor[i].getName());
}
EXAMPLE PROGRAM FOR JAVABEAN API
EventSetDescriptor eventSetDescriptor[] =
beanInfo.getEventSetDescriptors();
for(int i = 0; i < eventSetDescriptor.length; i++)
{ System.out.println("\t" +
eventSetDescriptor[i].getName());
}
}
catch(Exception e) {
System.out.println("Exception caught. " + e);
}
}
}
Bean name = Colors
OUTPUT
Properties:
rectangular
Events:
propertyChange
component
mouseMotion
mouse
hierarchy
key
focus
hierarchyBounds
inputMethod