Java Reference
In-Depth Information
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 addPropertyChangeLis-
tener 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 refl ect the change in property imageName . As usual,
the changes from the original version of the program will be shown in bold text.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
import animBeans.AnimBean 4 ;
public class AnimBeanApp3 extends JFrame
implements ActionListener, PropertyChangeListener
private AnimBean 4 sequence;
private JPanel speedControl, imageControl;
private JLabel delayPrompt, imagePrompt;
private JTextField delay, imageName;
public static void main(String[] args)
AnimBeanApp 3 frame = new AnimBeanApp 3 ();
public AnimBeanApp 3 ()
sequence = new AnimBean 4 ();
speedControl = new JPanel();
delayPrompt = new JLabel("Delay(ms): ");
delay = new JTextField(4);
imageControl = new JPanel();
imagePrompt = new JLabel("Image: ");
imageName = new JTextField(8);
add(sequence, BorderLayout.NORTH);
Search WWH ::

Custom Search