Javabean
Javabean
Definitions
A reusable software component that can be manipulated visually in a builder tool. (from JavaBean Specification) The JavaBeans API provides a framework for defining reusable, embeddable, modular software components.
Intro to JavaBeans
What are JavaBeans?
Software components written in Java Connect and Configure Components Builder Tools allow connection and configuration of Beans Begins Age of Component Developer Bringing Engineering methods to Software Engineering (e.g. electronics)
Persistence
Components can be stored and retrieved Default inherit serialization Can define more complex solutions based on needs of the components
Event Handling
Defines how components interact Java AWT event model serves as basis for the event handling APIs Provides a consistent way for components to interact with each other
Introspection
Defines techniques so components can expose internal structure at design time Allows development tools to query a component to determine member variables, methods, and interfaces Standard naming patterns used Based on java.lang.reflect
Creating a JavaBean
Requirements for a simple Bean Packaging Bean in a JAR file Additional Information BeanInfo Defining property editors Defining Bean customizers Naming Conventions
Bean Requirements
Introspection
Properties
Methods
Bean Requirements
Customization
Persistence
Other properties
Indexed properties
Bound properties
Constrained properties
BeanInfo class
Provides more information using FeatureDescripter objects Subclasses:
BeanInfo class
ICON to represent Bean Customizer Class (wizard for set up) Property Editor references List of properties with descriptions List of methods with descriptions Method to reset properties to defaults
The beanbox
Primary task is setting property values Property editors for common types
Creating a Bean
Usually extends Canvas (New window) Can extend Component (lightweight) Needs constructor with no arguments Paint() method used to display getPreferredSize(), getMinimumSize()
Class name: any Constructor: no argument or serialized template file Packaging: jar file with Java-Bean: True