Springer - An Introduction to Network Programming with Java_2

Page 332

322

An Introduction to Network Programming with Java

{ delay = delayIn; animTimer.setDelay(delay); } public Dimension getPreferredSize() { return new Dimension(140,120); } public void addPropertyChangeListener( PropertyChangeListener listener) { changeSupport.addPropertyChangeListener(listener); } public void removePropertyChangeListener( PropertyChangeListener listener) { changeSupport.removePropertyChangeListener( listener); } } Though the BDK provided a menu option to bind a property in one bean to a property (of the same type) in another bean, the Bean Builder does not. However, it is a relatively simple matter to modify example AnimBeanApp2 from the previous section to make use of the above bean, which is what the next example does. Example In this example, the application is going to act as a PropertyChangeListener, and so must implement method propertyChange. The application frame must be registered as a PropertyChangeListener for the bean by executing method addPropertyChangeListener on the bean, supplying an argument of this. When the String identifying the animation changes (i.e., when the value of property imageName changes), a PropertyChangeEvent will be generated and method propertyChange will be invoked. The simple action to be taken by this method will be to change the title of the application frame to reflect the change in property imageName. As usual, the changes from the original version of the program will be shown in bold text. import import import import import

java.awt.*; java.awt.event.*; javax.swing.*; java.beans.*; animBeans.AnimBean4;


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.