Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

Introduction to the JavaBeans API, Magercise 6
The StickFigure Bean with a Custom Property Editor

by John Zukowski, MageLang Institute

[Help | API Docs | Short Course | Magercises]

This Magercise focuses on the design and implementation of a custom property editor, as well as its specification within the bean-info class.

Magercise 6 Prerequisites

Skeleton Code

Tasks

  1. The first step is to create a working directory somewhere on your filesystem, hereafter referred to as workingdir.

  2. Next, create the directory stickfigure (all lowercase characters) directly under workingdir.

  3. Next, (1) save all the skeleton files, except the *.java files and GIF file, within workingdir and (2) save the *.java skeleton files and GIF file within stickfigure, that is, within workingdir/stickfigure.

  4. The next, and primary, task is to design and implement a custom "mood" property editor for the StickFigure Bean, MoodEditor. This class must extend PropertyEditorSupport and provide "mood" property-specific definitions for the following methods:

      public void setValue(Object o) { }
      public Object getValue() { }
      public String getAsText() { }
      public void setAsText(String s)
          throws IllegalArgumentException { }
      public String[] getTags() { }
    

  5. The next task is to augment the bean-info class, StickFigureBeanInfo. Add a getPropertyDescriptors() method that returns an array of two PropertyDescriptor instances for the "mood" and "sunburned" properties, respectively.

  6. Compile all JavaTM source files, *.java, from workingdir by including the stickfigure directory in the path specification.

  7. Build StickFigure.jar from workingdir by executing the file MakeStickFigureJar.bat (Windows) or MakeStickFigureJar.sh (UNIX).

  8. Next, load the StickFigure Bean into the BeanBox (or a comparable tool) using "LoadJar..." from the BeanBox "File" menu.

  9. Lastly, note the property editor for StickFigure Bean. The "mood" property should appear in the property sheet as a drop-down list. Verify that selecting different values from the list changes the image so that it displays a smile, frown, etc.

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

After loading the StickFigure Bean, it should appear in the palette, from where it can be selected and instantiated on the worksheet:

Notice the restricted number of properties displayed in the property sheet, as well as the custom "mood" property editor.

Magercise 7
Short Course
About This Short Course

Copyright © 1998-1999 MageLang Institute. All Rights Reserved.


[ This page was updated: 27-Oct-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.