Developing Java Beans changed, the getPropertyName() method may
Developing Java Beans for (int i = 0; i < cnt; i++) { PropertyChangeListener client = (PropertyChangeListener)v.elementAt(i); client.propertyChange(evt); } } } With this change in place, we have to change the implementation of the Thermometer class as well. Instead of implementing the TempChangeListener interface it will implement the PropertyChangeListener interface. We remove the tempChanged() method and replace it with a propertyChange() method. For the sake of simplicity, let's revert to the case where the Thermometer works with a single Temperature object named theTemperature instead of the two that we worked with previously. The code for the changed constructor and propertyChange() method is shown below: // constructorThermometer(Temperature temperature) { theTemperature = temperature; // register for property change eventstheTemperature.addPropertyChangeListener(this); } // handle the property change eventspublic void propertyChange(PropertyChangeEvent evt) { // determine if the CurrentTemperature property of the temperature // object is the one that changed if (evt.getSource() == theTemperature && evt.getPropertyName() == "CurrentTemperature") { Temperature t = (Temperature)evt.getSource(); // get the new value object Object o = evt.getNewValue(); double newTemperature; if (o == null) { // go back to the object to get the temperature newTemperature = t.getCurrentTemperature(); } else { // get the new temperature valuenewTemperature = ((Double)o).doubleValue(); } } } The propertyChange() method first determines if the source of the event was its instance of the Temperature class, and if the property that changed is called CurrentTemperature. If these two things are true, the source is cast to type Temperature and the new value object is retrieved from the event object. Since the new value object can be null, there is a check for that condition. If it is page 58
Note: If you are looking for inexpensive but high quality provider to host and run your jsp application check Astra jsp hosting services