Download - Javabeans-4
-
8/7/2019 Javabeans-4
1/11
Object is an runtime instance of a class.
Software component is an reusable
object that can be plugged into anysoftware application.
Ex:
Spell check utility, calculator, find and
replace utility. Reusable software components can be
simple, such as buttons, text fields, listboxes, scrollbars, and dialogs.
-
8/7/2019 Javabeans-4
2/11
JavaBeans is a portable, platform-independent component model written
in theJava programming language.
Java Bean is a reusable softwarecomponent that can be used in varietyof different environment and it can be
manipulated visually in a builder tool. With the JavaBeans API you can create
reusable, platform-independentcomponents.
-
8/7/2019 Javabeans-4
3/11
Beans are dynamic in that they can bechanged or customized through thedesign mode of a builder tool.
It posses properties, methods, and
events.
These can be developed using a toolcalled Bean Developer Kit(BDK)
-
8/7/2019 Javabeans-4
4/11
A Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm.
The properties, events, and methods of a Beanthat are exposed to an application
builder tool can be controlled. A Bean may be designed to operate correctly
in different locales, which makes ituseful in global markets.
Auxiliary software can be provided to help a
person configure a Bean. This software isonly needed when the design-time parametersfor that component are being set. Itdoes not need to be included in the run-timeenvironment.
-
8/7/2019 Javabeans-4
5/11
The configuration settings of a Bean canbe saved in persistent storage and
restored at a later time. A Bean may register to receive events
from other objects and can generateevents that are sent to other objects.
-
8/7/2019 Javabeans-4
6/11
Support forintrospection
x so that a builder tool can analyze how a bean works
Support forcustomization
x so that when using an application builder a user cancustomize the appearance and behavior of a bean
Support foreventsx as a simple communication metaphor than can be used
to connect up beans
Support forproperties
x both for customization and for programmatic use
Support forpersistence
x so that a bean can be customized in an applicationbuilder and then have its customized state saved awayand reloaded later
-
8/7/2019 Javabeans-4
7/11
A mechanism that allows the builder toolto analyze a bean.
Two ways to analyze a bean: low-level reflection APIs.
vendor provided explicit information(Customization).
Application builder will provide defaultBeanInfo class BeanInfo.
-
8/7/2019 Javabeans-4
8/11
package acme.beans;
import java.awt.*;
import java.io.Serializable;
public class Acme04Bean extends Canvas implements Serializable {
public Acme04Bean() {
resize(60,40);
this.label="Bean";
setFont(new Font("Dialog", Font.PLAIN, 12));
}
-
8/7/2019 Javabeans-4
9/11
public void paint(Graphics g) {
g.setColor(beanColor);
g.setColor(Color.blue);
int width = size().width;int height = size().height;
FontMetrics fm = g.getFontMetrics();
g.drawString(label, (width - fm.stringWidth(label)) / 2,
(height + fm.getMaxAscent() - fm.getMaxDescent()) / 2);
}
public Color getColor() {
return beanColor;
}
-
8/7/2019 Javabeans-4
10/11
-
8/7/2019 Javabeans-4
11/11
Purpose:
To use existing data formats and plug into OLE orOpenDoc documents (e.g., Excel doc inside a Word doc)
To be trivial for the common case of a tiny Bean (bysaving its internal state)
Solutions
Externalization: provides a Bean with full control over theresulting data layout.
Serialization: provides an automatic way of storing out andrestoring the internal state of a collection of Java objects
All bean must support either Serialization or Externalization