30.9. List Cell Renderer

 
[Page 898 ( continued )]

27.2. JavaBeans

JavaBeans is a software component architecture that extends the power of the Java language by enabling well-formed objects to be manipulated visually at design time in a pure Java builder tool, such as NetBeans, JBuilder, or Eclipse. Such well- formed objects are referred to as JavaBeans or simply beans . The classes that define the beans, referred to as JavaBeans components or bean components , or simply components , conform to the JavaBeans component model with the following requirements:

  • A bean must be a public class.

  • A bean must have a public no-arg constructor, though it can have other constructors if needed. For example, a bean named MyBean must either have a constructor with the signature

       public   MyBean(); 

    or have no constructor if its superclass has a no-arg constructor.

  • A bean must implement the java.io.Serializable interface to ensure a persistent state.

  • A bean usually has properties with correctly constructed public accessor (get) methods and mutator (set) methods that enable the properties to be seen and updated visually by a builder tool.

  • A bean may have events with correctly constructed public registration and deregistration methods that enable it to add and remove listeners. If the bean plays a role as the source of events, it must provide registration methods for registering listeners. For example, you can register a listener for ActionEvent using the addActionListener method of a JButton bean.

The first three requirements must be observed , and therefore are referred to as minimum JavaBeans component requirements . The last two requirements are dependent on implementations . It is possible to write a bean without get/set methods and event registration/deregistration methods.

A JavaBeans component is a special kind of Java class. The relationship between JavaBeans components and Java classes is illustrated in Figure 27.1.

Figure 27.1. A JavaBeans component is a serializable public class with a public no-arg constructor.


[Page 899]

Every GUI class is a JavaBeans component, because

  1. it is a public class,

  2. it has a public no-arg constructor, and

  3. it is an extension of java.awt.Component , which implements java.io.Serializable .

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net