Professional Documents
Culture Documents
Prifysgol Caerdydd
Ysgol Cyfrifiadureg a Gwybodeg
JavaBeans
Robert Evans
c
Copyright
2010 Robert Evans.
Email: Robert.Evans@cs.cardiff.ac.uk
Abstract
This Note describes how to use the Java Beans Development Kit on Linux.
Contents
1 JavaBeans and the Bean Development Kit 1
1.1 The BDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Running the BeanBox . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Adding beans to the canvas . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Wiring up events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
% bdk-user-setup
This will create a directory called BDK1.1 and sub-directories BDK1.1/jars and
BDK1.1/beanbox together with some links to files in the Bean Development Kit in-
stallation directory.
% cd BDK1.1/beanbox
% ./run.sh &
The BeanBox starts and loads beans from the JAR (Java Archive) files in the BDK1.1/jars
directory. It then displays four windows on the screen:
the ToolBox which lists all beans the BeanBox has found,
the BeanBox which is a canvas where you will drop beans and connect them
together,
the Properties sheet which is used to set the properties of the current bean,
bean to appear. The bean that appears on the BeanBox canvas is the current selected
bean (shown by a hatched border around the bean) and its properties appear in the
Properties sheet.
The properties in the Properties sheet can be edited by typing new values or by spe-
cial editors (eg for colours). For example, in the diagram below, we have added two
ExplicitButton beans and a Juggler bean to the canvas. Click on the left hand bean
labelled Press. This bean becomes the current selected bean.
Scroll down and choose stopJuggling. Click on OK. The actionPerformed event
from the Stop button will now cause the stopJuggling method of the Juggler bean to
be called. In order to cause this to happen, the BeanBox generates adapter code,
compiles it and loads it automatically.
So clicking on the Stop button now stops the Juggler.
You can similarly set up a Start button to restart the Juggler. Choose the other Press
button on the canvas, rename it Start, choose EditEventsbutton pushactionPerformed
and this time select startJuggling from the EventTargetDialog window.
1.5 Documentation
For more information refer to the Web-based documentation at URL
http://www.cs.cf.ac.uk/applications/java/BDK1.1/.
a file, called the manifest, which specifies which class files in the archive are
beans,
all the class files associated with the component (the bean),
any data files (eg image files) needed by the bean.
Subsequent sections tell you how to create the JAR file and how to load the JAR file
into the BeanBox so that it can use your bean.
% mkdir directory-name
to create the directory where directory-name is the name of the directory, e.g. ImageViewer,
then copy or create the source files there.
So, for the ImageViewer bean we have:
Information for Users: Introductory Note 615 5
% ls -l ImageViewer
total 68
-rw-r--r-- 1 robert 45724 Jun 1 15:39 Cay.gif
-rw-r--r-- 1 robert 1105 Jun 1 15:39 ImageViewerBean.java
-rw-r--r-- 1 robert 20132 Jun 1 15:39 Tower.gif
File ImageViewerBean.java is the Java source file and the .gif files are data files
used by the bean to draw images.
To turn these files into a JavaBean, change to the ImageViewer directory and type
makebean followed by the names of the Java and data files which make up the bean:
The bean is given the same name as the first Java file on the makebean command
line. (In this case, there is only one Java file and the bean is called ImageViewerBean).
The makebean command has made the ImageViewerBean.jar JavaBean JAR
archive and three other files:
% ls -l
total 137
-rw-r--r-- 1 robert 45724 Jun 1 15:39 Cay.gif
-rw-r--r-- 1 robert 1597 Jun 2 10:53 ImageViewerBean.class
-rw-r--r-- 1 robert 525 Jun 2 10:53 ImageViewerBean.gmk
-rw-r--r-- 1 robert 67275 Jun 2 10:53 ImageViewerBean.jar
-rw-r--r-- 1 robert 1105 Jun 1 15:39 ImageViewerBean.java
-rw-r--r-- 1 robert 48 Jun 2 10:53 ImageViewerBean.mf
-rw-r--r-- 1 robert 20132 Jun 1 15:39 Tower.gif
Name: ImageViewerBean.class
Java-Bean: True
The manifest file tells the BDK to display the bean ImageViewerBean in its ToolBox
when the JAR files is loaded.
ImageViewerBean.gmk is a makefile which makebean supplies to GNU make in
order to compile the Java source and build the JAR file. Makebean runs GNU make
for you, you do not have to do it yourself. ImageViewerBean.class is the class file
which has been compiled from ImageViewerBean.java. There is a copy of it in the
JAR file.
would create a JavaBean called MyBean in a file MyBean.jar. As in the case of Im-
ageViewerBean, makebean will create a manifest file specifying that the class com-
piled from the first named Java file is a bean.
Name: MyBean.class
Java-Bean: True
If more than one class file in the archive is to be a bean, you must create the manifest
file yourself before running makebean.
% mv ImageViewerBean.jar /BDK1.1/jars
The new bean will appear in the ToolBox when you next start the BeanBox (with
./run.sh).
Alternatively, you can load any JavaBean JAR file into the BeanBox by choosing
FileLoadJar... from the BeanBox menu and browsing for your JAR file.