Java Reference
In-Depth Information
2. Within the setSharesTraded() method, notify all listeners that the
property is about to be changed before changing the property. If any
listener vetoes, be sure that the property does not change.
3. Save and compile the Stock class.
4. Write a bean called StockVetoer that implements the
VetoableChangeListener interface.
5. Within the vetoableChange() method, determine how many shares
are being traded. If the value is greater than 5000, veto the change.
6. Save and compile the StockVetoer class.
7. Modify your manifest file so that StockVetoer is denoted as a Java-
Bean. Create a new JAR file that contains both the Stock and
StockVetoer beans.
8. Load this JAR file in the Bean Builder, and hook these two beans
together to verify that they are working.
You should not be able to change the sharesTraded property of the
Stock bean to a value greater than 5000.
Lab 19.4: User-Defined Events
To become familiar with writing beans that fire events. In this lab, you
will modify your Stock bean so that it fires a StockPriceChange event.
1. Write a class named StockPriceChangeEvent that extends EventObject.
Add a field named price and a constructor that initializes the field.
2. Save and compile the StockPriceChangeEvent class.
3. Write an interface named StockPriceChangeListener that contains
two methods: priceIncreased() and priceDecreased().
4. Save and compile the StockPriceChangeListener interface.
5. Modify your Stock bean class so that it is the source of stock-
PriceChange events.
6. Within the setPrice() method, notify all listeners that the price of the
stock is changing.
7. Save and compile the Stock bean class.
8. Create a manifest file and JAR file for these classes.
Search WWH ::




Custom Search