FileDocCategorySizeDatePackage
ExampleApplet4.javaAPI DocExample6132Tue Jun 03 23:07:30 BST 1997None

NumberLabel

public class NumberLabel extends Label implements PropertyChangeListener

Fields Summary
protected PropertyChangeSupport
boundSupport
protected VetoableChangeSupport
vetoSupport
protected int
theValue
Constructors Summary
public NumberLabel(String text)


   // constructor
     
   
      // call the super class
      super(text);

      // construct the support objects
      boundSupport = new PropertyChangeSupport(this);
      vetoSupport = new VetoableChangeSupport(this);
   
Methods Summary
public voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)

      // defer to the support object
      boundSupport.addPropertyChangeListener(l);
   
public voidaddVetoableChangeListener(java.beans.VetoableChangeListener l)

      // defer to the support object
      vetoSupport.addVetoableChangeListener(l);
   
public intgetValue()

      return theValue;
   
public voidpropertyChange(java.beans.PropertyChangeEvent evt)

      // only interested in changes to Value properties
      if (evt.getPropertyName().equals("Value"))
      {
         // just change our own property
         Integer val = (Integer)evt.getNewValue();

         try
         {
            setValue(val.intValue());
         }
         catch (PropertyVetoException e)
         {
         }
      }
   
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)

      // defer to the support object
      boundSupport.removePropertyChangeListener(l);
   
public voidremoveVetoableChangeListener(java.beans.VetoableChangeListener l)

      // defer to the support object
      vetoSupport.removeVetoableChangeListener(l);
   
public voidsetValue(int newValue)

      // fire the change to any constrained listeners
      vetoSupport.fireVetoableChange("Value", new Integer(theValue),
                                       new Integer(newValue));

      // no veto, so save the old value and then change it
      Integer oldVal = new Integer(theValue);
      theValue = newValue;
      setText(String.valueOf(theValue));
      repaint();

      // fire the change to any bound listeners
      boundSupport.firePropertyChange("Value", oldVal,
                                  new Integer(theValue));