Beruflich Dokumente
Kultur Dokumente
Blue Button
Explicit Button
Our Button
Event Monitor
Jelly Bean
Molecule
Etc
How to get an instance of already
available bean
Position the cursor on the toolbox entry
labeled with the necessary bean.
Click and drag to the bean box.
It will be placed with hatched border
Can reposition the bean wherever we
want
Can change the value using properties
window.
Introspection of Bean
Introspectionis the process of analyzing a
bean to determine its capabilities.
Bean indicates which of its properties,
events and methods should be exposed
by an application builder
How to design our own properties of our
bean
Design patterns for properties
A property is a subset of a beans state.
The value assigned to the properties
determine the behavior and appearance
of that component
3 types of properties
Simple properties
Boolean properties
Indexed properties
Simple Properties
A simple property has a single value
Public T getN();
Public void setN(T arg);
EX:
public double getDepth()
public void setDepth(double d)
Boolean Properties
A boolean property has a value of true or
false
public boolean isN();
public boolean getN();
public booean setN(boolean value);
N-name of the property
Indexed Property
Anindexed property consist of multiple
values
public T getN(int index);
public void setN(int index, T value);
public T[] getN();
public void setN(T values[]);
Events in Bean Box
ActionEvent (generated when a button
is presses, a list item is double clicked
or a menu is selected)
AdjustmentEvent (generated when a
scroll bar is manipulated)
ComponentEvent (generated when a
component is hidden, moved, resized)
ContainerEvent (generated when a
component is added or removed from a
container)
Events in Bean box
FocusEvent (generated when a
component gains or loses keyboard
focus)
InputEvent (Abstract super class for all
component input event classes)
ItemEvent (generated when a checkbox
or list item is selected)
KeyEvent (generated when input is
received from the keyboard)
Events in Bean box
MouseEvent (generated when the mouse
is dragged,moved,clicked,pressed or
released)
MouseWheelEvent (generated when the
mouse wheel is moved)
TextEvent (generated when the value of
text area or text field is changed)
WindowEvent ( generated when a
window is activated , closed,
deactivated etc.
Design Patterns for Events
Allthe events specified above are supported by
beans
public void addTListener(TListener eventListener);
public void addTListener(TListener eventListener)
throws TooManyListeners;
public void removeTListener(TListener eventListener);
T type of the event.
EX:
public void addActionListener(ActionListener eventListener)
public void addMouseListener(MouseListener
eventListener)
Developing a simple bean using BDK
Start BDK
Test
Creating a directory for the new bean
c:\bdk\demo\sunw\demo\mybean
Create the source file for the new bean
public class MyBean implements java.io.Serializable
{
protected int theValue;
public MyBean()
{
}
public void setMyValue(int newValue)
{
theValue = newValue;
}
public int getMyValue()
{
return theValue;
}
}
Compile the source file
Javac mybean.java
Create a manifest file(mybean.mft)
Name:sunw/demo/mybean/mybean.class
Java-Bean:true
Generate a JAR file
Jar
cfm mybeans.jar
sun/demo/mybean/mybean.mft
Start the BDK
The toolbox window in bdk will include an
entry labeled Mybean for your new bean
Bean
Customization
When you are using a visual development tool to assemble components
into applications, you will be presented with some sort of user
interface for customizing Bean attributes.
These attributes may affect the way the Bean operates or the way it
looks on the screen.
The application tool you use will be able to determine the properties
that a Bean supports and build a property sheet dynamically.
This property sheet will contain editors for each of the properties
supported by the Bean, which you can use to customize the Bean to
your liking.
The Beans class library comes with a number of property editors for
common types such as float, boolean, and String.
If you are using custom classes for properties, you will have to create
custom property editors to associate with them.
In some cases the default property sheet that is created by the
development tool will not be good enough.
You may be working with a Bean that is just too complex to customize
easily using the default sheet.
Beans developers have the option of creating a customizer that can
help the user to customize an instance of their Bean. You can even
create smart wizards that guide the user through the customization
process.
Customizers are also kept separate from the Bean class so that it is not
a burden to the Bean when it
is not being customized. This idea of separation is a common theme in
the JavaBeans architecture.
A Bean class only has to implement the functionality it was designed
for; all other supporting features are implemented separately.
Bean Persistence