A browser with JavaScript enabled is required for this page to operate properly.
Documentation

The Java™ Tutorials
Writing JavaBeans Components
Properties
Methods
Events
Using a BeanInfo
Trail: JavaBeans(TM)
« PreviousTrailNext »

The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
See Dev.java for updated tutorials taking advantage of the latest releases.
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.

Lesson: Writing JavaBeans Components

Writing JavaBeans components is surprisingly easy. You don't need a special tool and you don't have to implement any interfaces. Writing beans is simply a matter of following certain coding conventions. All you have to do is make your class look like a bean — tools that use beans will be able to recognize and use your bean.

However, NetBeans provides some features that make it easier to write beans. In addition, the Java SE API includes some support classes to help implement common tasks.

The code examples in this lesson are based on a simple graphic component called FaceBean.

FaceBean source code only:
FaceBean.java
Entire NetBeans project including FaceBean source code:
FaceBean.zip

A bean is a Java class with method names that follow the JavaBeans guidelines. A bean builder tool uses introspection to examine the bean class. Based on this inspection, the bean builder tool can figure out the bean's properties, methods, and events.

The following sections describe the JavaBeans guidelines for properties, methods, and events. Finally, a section on BeanInfo shows how you can customize the developer's experience with your bean.

« PreviousTrailNext »

Previous page: Previous Lesson
Next page: Properties

AltStyle によって変換されたページ (->オリジナル) /