Assignment-07

 

 

 

Foreword

Resources

Code Listings

Foil Sets

Assignments

Solutions

External Resources

SiteMap

Search

Home

Up ] Assignment-01a ] Assignment-01b ] Assignment-01c ] Assignment-01d ] Assignment-02 ] Assignment-02a ] Assignment-03 ] Assignment-03a ] Assignment-03b ] Assignment-03c ] Assignment-03d ] Assignment-04 ] Assignment-04a ] Assignment-04b ] Assignment-05 ] Assignment-06 ] [ Assignment-07 ]

Java Beans

In this assignment, you are to take an existing bean with a visualization such as the TextEditor bean shown in class, make some small modifications to have methods that can be the target of events, and use it in the beanbox to make a new bean with buttons.

Making a bean and Using a bean in the beanbox

I will describe here how to take the TextEditor code and make it into a loadable bean jar file. This example is described in this html page.

1. Make a directory where you will work with beans. Copy the example directories there.

    cp -r ~njm/public_html/JavaBeanExample/demo . 
    cp -r ~njm/public_html/JavaBeanExample/jars .

2. Change directory to the demo directory. You can either use the Makefile to prepare your jars file, or follow these directions. The steps are to compile java, make the manifest file and the jar file, but note that the manifest file is already made in this directory.

    javac sunw/demo/TextEditor/*.java
    jar cfm ../jars/TextEditor.jar manifest.txt sunw/demo/TextEditor/*.class sunw/demo/TextEditor/*.gif

These directions compiled the files TextEditor.java and TextEditorBeanInfo.java and put the jar file in the jars directory one level up. (For me that was ~njm/public_html/JavaBeanExample/jars.)

3. Now you can load this bean into the beanbox. To run the beanbox

    cd /usr/npac/BDK/beanbox
    run.sh &

When the beanbox windows come up, if you are on an SGI, you must move each window to make the contents appear.

Under the file menu, do LoadJar. In the file dialog box, replace the directory with your jars directory (mine was ~njm/public_html/JavaBeanExample/jars) in the upper textfield, and give the name of the bean, TextEditor.jar in the lower textfield. The bean now appears in the Toolbox (Note that it's named TextEditor2 since there was already a TextEditor bean.) For more information on hooking up events and changing properties, check out the page on Running the Beanbox

4. Using the bean in the toolbox and making a new bean: You can place your bean in the beanbox window. I did an example using TextEditor bean where I placed a button (ExplicitButton) in the beanbox window and hooked up its event to the selectAll method of TextEditor, and I customized the colors and initial text. Then you can make a new bean by using Save under the file menu. In the file dialog box, type your jars directory and the new name of the file in the form NewName.jar.

5. Now the new bean can be loaded back into the beanbox whenever you want to use it. To try this out, clear the beanbox window. Then use the Load on the file menu. Don't use the LoadJar as the beanbox doesn't prepare a manifest file. This means that your new bean will load directly into the beanbox window, instead of onto the toolbox. (Remember that the beanbox doesn't do everything right!)

6. You can also make an applet out of your new bean. Use MakeApplet on the file menu. The applet files will include a jar file, an html file and other stuff in a directory which the beanbox insists that everyone's applet is stored in its directory /usr/npac/BDK/beanbox/tmp. So please in the file dialog box, go to Choose Jar File and name your applet something unique. For example, in the upper textfield change it to /usr/npac/BDK/beanbox/tmp/NancyApplet/NancyApplet.jar. Then in the lower textfield also type NancyApplet.jar. In the file dialog box, you must then give the applet name NancyApplet. Now you can copy your applet directory from /usr/npac/BDK/beanbox/tmp to your web directory and view the URL that ends in NancyApplet/NancyApplet.html.

Your Assignment

1. Make a bean. It is sufficient to change the TextEditor bean. You may add one or more properties and you must at least add a new method that can be used as the target of events. Note that due to limitations of the beanbox, these methods must take no parameters and return no result. For example, you could add a method

    public void clear()

that cleared the text from the TextArea. Or you could add methods that set particular properties, such as

    public void setgreen()
    public void setred()
    etc.

2. Now make your bean into a jar and load it into the beanbox. Place some buttons to hook up to your new methods. So the above methods could be the target of buttons labelled Clear, Change to Green, Change to Red, and so on.

3. Save your new bean.

4. To complete your assignment, write an html page describing what bean you worked with, what new properties and methods you introduced, and how you made the new bean. In your description, you can also tell us if you made other experiments with the beanbox and if you ran across things that didn't work. On your html page, you can put links to all relevent .java files and also give the location of the .jar files so that we can load them into the beanbox and grade them.