Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Properties of Beans Is subset of a component state are aspects of a Bean’s appearance and behavior that are changeable at design time are private values accessed through get and set methods Simple Properties Contains one value that may be either a simple type or a object Property get and set method names follow specific rules called design patterns Using design pattern-based method names, JavaBeans-enabled builder tools can Discover a Bean’s properties Determine the properties read/write attributes Determine the properties type Locate an appropriate property editor for each property type Display the properties(usually in a property sheet) Alter those properties(at design time) Naming patterns public T getN() public void setN(T value) T is the type of the property and N is its name A property typically has these both of these methods a read-only property has only the getN() method a write-only property has only the setN() method Boolean Properties Contains one value that may be either true or false Naming patterns to read the property to write the property public boolean isN() public boolean getN() public void setN(boolean value) N is the name of the property Indexed Properties Contains several values that may be either simple types or objects Represent collection of values accessed by index public T getN(int index) T is the type and N is its name reads one value where index identifies which entry is wanted public T[] getN() public void setN(int index, T value) All values may be retrieved writes one value the argument index identifies which entry to change, and the argument value is the new value for that property public void setN(T values[]) All values may be updated the argument values is an array that contains the new values for the property Bound Property Allow one bean to notify other components about relevant changes to its prperties When a bound property is changed, a property change event is multicast to other beans to inform them of this update convenient mechanism to communicate a change in the property among a set of components PropertyChangeEvent class In java.beans package defines the event notifications that are multicast by a bean when one of its bound properties is changed PrpertyChangeEvent( Objetc src, String pname, Object oValue, Object nValue) src is the bean whose property has changed pname - the name of the property oValue, nValue - old and new values of the property Methods Object getNewValue() returns an Object with the new value of the property Object getOldValue() returns an Object with old value of the property String getPropertyName() returns the string equivalent of the property name PropertyChangeListener interface In the java.beans package to receive PropertyChangeEvent notifications defines one method void propertyChange (PropertyChangeEvent pce) PropertyChangeSupport class In java.beans package used to perform much of the work associated with bound properties PropertyChangeSupport(Object src) src is the bean whose bound property is changed synchronized void addPropertyChangeListener (PropertyChangeListener pcl) method registers the listener for property change events synchronized void removePropertyChangeListener( PropertyChangeListener pcl) method unregisters the listener for property change events void firePropertyChange(String pname, Object oldValue, Object newValue) Via this method A property change notification is multicast to the listeners pname - the name of the property oldValue, newValue - old and new values of that property Constrained Properties When a constrained property is changed, an event notification can be multicast to other Beans to inform them of the proposed modification the listeners may accept the update it is also possible for one or more listeners to veto the change in that case, the source receives an exception and restores the property to its old value VetoableChangeListener interface In the java.beans package used to receive PropertyChangeEvent notification when constrained properties are changed defines one method void vetoableChange(PropertyChangeEvent pce) throws PropertyVetoException implementation of this method should throw an exception if it wants to reject the property change PropertyVetoException class In the java.beans package PropertyVetoException(String message, PropertyChangeEvent pce) message - is a String that is presented to the user if the property change is rejected pce - is a reference to the PropertyChangeEvent object VetoableChangeSupport class In the java.beans package used to perform much of the work associated with constrained properties VetoableChangeSupport(Object src) src - is the bean whose constrained property is changed Methods synchronized void addVetoableChangeListener (VetoableChangeListener pcl) register the listener for property change events associated with constrained properties synchronized void removeVetoableChangeListener (VetoableChnageListener pcl) unregister the listener for property change events associated with constrained properties Void fireVetoableChange(String pname, Object oldValue, Object newValue) throws PropertyVetoException method multicasts a notification about a property change to the listeners pname - name of the property oldValue, newValue - the old and new values of the property