NetBeans: The Definitive Guide
by Tim Boudreau, Jesse Glick, Simeon Greene, Vaughn Spurlin, Jack J. Woehr
Chapter 9. JavaBeans
Why Should I Make Beans?
You should make JavaBeans to encourage reuse of your Java code. JavaBeans is the standard architecture for building reusable components in Java. Originally intended as visual components for building GUIs, now the JavaBeans are widely used in all Java environments, including JSP and EJB development. Like components in other object-oriented programming languages, JavaBeans have properties that can be set at design-time by visual design tools or at runtime by the containing program.
If you want other developers to use your code, if you want your components to snap together with ease, if you want to spend your time developing application logic instead of debugging interfaces, make JavaBeans. For a deeper understanding of the JavaBeans architecture, see Sun’s JavaBeans Technology (http://java.sun.com/beans) page or read Developing JavaBeans by Robert Englander (O’Reilly).
Creating JavaBeans
We will continue with the
AddStrings example
from the last chapter to demonstrate NetBeans features for developing
JavaBeans. It is not necessary to go through all
this to create a Bean from scratch. Simply follow the procedure for
creating a new Java object, and use the Bean template.
We’re taking the long route to show more ways that
NetBeans can help. Here’s the plan:
Create a GUI component from the
AddStrings JFrame.Convert the component into a proper Bean.
Add an event set to inform the container about changes to Bean properties.
Generate a
BeanInfo ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access