Java Examples in a Nutshell, 3rd Edition
The JavaBeans API provides a framework for defining reusable, embeddable, modular software components. The JavaBeans specification includes the following definition of a bean: "a reusable software component that can be manipulated visually in a builder tool." As you can see, this is a rather loose definition; beans can take a variety of forms. At the simplest level, individual GUI components are all beans, while at a much higher level, an embeddable spreadsheet application might also function as a bean. Most beans, however, probably fall somewhere between these two extremes. Note that the definition of a Java bean explicitly supposes the existence of a visual GUI builder tool. In this chapter, we'll use the term "beanbox" to refer to any such tool. The name is from an obsolete JavaBeans demonstration tool shipped by Sun with the early releases of JavaBeans. A new tool, called "Bean Builder," has replaced the beanbox, and you can download it from http://java.sun.com/products/javabeans if you do not already have a bean-enabled development environment. One of the goals of the JavaBeans model is interoperability with similar component frameworks. So, for example, a native Windows program can, with an appropriate bridge or wrapper object, use a Java bean as if it were a COM or ActiveX component. The details of this sort of interoperability are beyond the scope of this chapter, however. Beans can be used at three levels, by three different categories of programmers:
This chapter explains how to use the JavaBeans API at the second and third levels: how to write beans and their auxiliary classes, and how to write programs that manipulate beans. The emphasis is on writing beans, but Example 15-10 shows the Bean class, which implements the inner workings for the ShowBean beanbox of Chapter 11. Contents of this chapter include:
|