Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
8Activity
0 of .
Results for:
No results containing your search query
P. 1
Java Beans

Java Beans

Ratings: (0)|Views: 718|Likes:
Published by Adarsh

More info:

Published by: Adarsh on May 31, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

01/23/2011

pdf

text

original

 
JavaBeans
JavaBeans™ is a portable, platform-independent componentmodel written in the Java programming language. The JavaBeansarchitecture was built through a collaborative industry effort andenables developers to write reusable components in the Javaprogramming language.With the JavaBeans API you can create reusable, platform-independent components. Using JavaBeans-compliant applicationbuilder tools, you can combine these components into applets,applications, or composite components.JavaBean components are known as
beans
. Beans are dynamicin that they can be changed or customized. Through the design modeof a builder tool, you use the property sheet or bean customizer tocustomize the bean and then save (persist) your customized beans.
JavaBeans Concepts
The JavaBeans™ architecture is based on a component modelwhich enables developers to create software units called
components
.Components are self-contained, reusable software units that can bevisually assembled into composite components, applets, applications,and servlets using visual application builder tools. JavaBeancomponents are known as
beans
.A set of APIs describes a component model for a particularlanguage. The JavaBeans API
describes the core detailedelaboration for the JavaBeans component architecture.Beans are dynamic in that they can be changed or customized.Through the design mode of a builder tool you can use the Propertieswindow of the bean to customize the bean and then save (persist)your beans using visual manupulation. You can select a bean from thetoolbox, drop it into a form, modify its appearance and behavior, defineits interaction with other beans, and combine it and other beans intoan applet, application, or a new bean.The following list briefly describes key bean concepts.
Builder tools discover a bean's features (that is, its properties,methods, and events) by a process known as
introspection
.Beans support introspection in two ways:
o
By adhering to specific rules, known as
design patterns
,when naming bean features. The
classexamines beans for these design patterns to discover bean
11
 
features. The
Introspector
class relies on the
core reflection
API. The trailThe Reflection APIis an excellent place tolearn about reflection.
o
By explicitly providing property, method, and eventinformation with a related
bean information
class. A beaninformation class implements the
BeanInfo
interface. A
BeanInfo
class explicitly lists those bean features that are tobe exposed to application builder tools.
Properties
are the appearance and behavior characteristics of abean that can be changed at design time. Builder tools introspecton a bean to discover its properties and expose those propertiesfor manipulation.
Beans expose properties so they can be customized at designtime.
Customization
is supported in two ways: by using propertyeditors, or by using more sophisticated bean customizers.
Beans use
events
to communicate with other beans. A bean thatis to receive events (a listener bean) registers with the bean thatfires the event (a source bean). Builder tools can examine abean and determine which events that bean can fire (send) andwhich it can handle (receive).
Persistence
enables beans to save and restore their state. Afterchanging a bean's properties, you can save the state of the beanand restore that bean at a later time with the property changesintact. The JavaBeans architecture uses Java Object Serializationto support persistence.
A bean's
methods
are no different from Java methods, and canbe called from other beans or a scripting environment. By defaultall public methods are exported.Beans vary in functionality and purpose. You have probably met someof the following beans in your programming practice:
GUI (graphical user interface)
Non-visual beans, such as a spelling checker
Animation applet
Spreadsheet application
22
 
Writing a Simple Bean
In this section you will learn more about beans by performing thefollowing actions:
Creating a simple bean
Compiling the bean
Generating a Java Archive (JAR) file
Loading the bean into the GUI Builder of the NetBeansIDE
Inspecting the bean's properties and eventsYour bean will be named
SimpleBean
. Here are the steps to create it:
1.Write the
SimpleBean
code
. Put it in a file named
SimpleBean.java
, in the directory of your choice. Here's thecode:
import java.awt.Color;import java.beans.XMLDecoder;import javax.swing.JLabel;import java.io.Serializable;public class SimpleBean extends JLabelimplements Serializable {public SimpleBean() {setText( "Hello world!" );setOpaque( true );setBackground( Color.RED );setForeground( Color.YELLOW );setVerticalAlignment( CENTER );setHorizontalAlignment( CENTER );}}SimpleBean
extends the
graphic component andinherits its properties, which makes the SimpleBean a visualcomponent.
SimpleBean
also implements the
interface. Your bean may implement either the
Serializable
or the
Externalizable
interface.
2. Create a manifest, the JAR file, and the class fileSimpleBean.class
. Use the Apache Ant tool to create these files.Apache Ant is a Java-based build tool that enables you to generateXML-based configurations files as follows:
<?xml version="1.0" encoding="ISO-8859-1"?><project default="build">
33

Activity (8)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Sunil Soni liked this
Rajesh Kumar liked this
Vipin Jain liked this
ilijarosandic liked this
arisan_602000 liked this
andTesfy liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->