Java Reference
In-Depth Information
4. Save and compile the Stock class.
5. Create a manifest file for the Stock bean, and use it to package the
Stock bean in a JAR file.
6. Open the Stock bean in the builder tool, and change some of its
properties.
Because this Stock bean is a GUI component, you should be able to see
its properties displayed on the bean itself. You may need to force a
repaint by covering up the design window and then restoring it.
Lab 19.2: Using Bound Properties
In this lab, you will modify the Stock bean so that its properties are
bindable.
1. Open your Stock.java file from Lab 19.1. Add a field of type
PropertyChangeSupport, and initialize this field in the constructor.
2. Add the necessary add and remove methods so that other beans can
register themselves as PropertyChangeEvent listeners.
3. Within the set methods of the Stock bean, invoke the fireProperty-
Change() method of the PropertyChangeSupport object, passing in
the appropriate arguments.
4. Save and compile the Stock class.
5. Re-create the JAR file, and reload it in the Bean Builder.
6. Add a Stock bean to the design window and a JSlider component.
Bind the Stock's price property to the value property of the JSlider.
Change the price property of the Stock bean, and you should see the
JSlider move accordingly.
Lab 19.3: Using Constrained Properties
To become familiar with constrained properties. In this lab, you will
modify the Stock bean so that its sharesTraded property is constrained.
1.
Add the necessary fields and methods to make the Stock class able
to handle VetoableChange listeners.
Search WWH ::




Custom Search