import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.beans.*;

public class BeanTest extends Applet implements MouseListener
{
	CustomBean cBean;
	Button b;
	     
    public void init() 
    {
	setLayout(new BorderLayout());
	cBean = new CustomBean();
        b = new Button("color");
        b.addMouseListener(this);
        Color tempColor=cBean.getColor();
        String iniColor="red";
        if(tempColor==Color.green)
        	iniColor="green";      
        BeanListener bl = new BeanListener(iniColor);
        cBean.addPropertyChangeListener(bl);
        add("Center", cBean);
	add("South",b);
	add("East",bl);
   }

    public void destroy() {
        remove(cBean);
        remove(b);
    }

    public void mousePressed(MouseEvent e) 
    {
	if(e.getSource()==b)
	{
	if(cBean.getColor()==Color.red)
        cBean.setColor(Color.green);
        else
        cBean.setColor(Color.red);
	}
   }

    public void mouseReleased(MouseEvent e) {
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }

    public void mouseClicked(MouseEvent e) {
    }

    public static void main(String args[]) {
	Frame f = new Frame("BeanTest");
	BeanTest bTest = new BeanTest();
	bTest.init();
	bTest.start();

	f.add("Center", bTest);
	f.setSize(250, 250);
	f.show();
    }
    public String getAppletInfo() {
        return "A simple bean test program.";
    }
}

class BeanListener extends Panel                                    
                  implements PropertyChangeListener
{      
    TextField s;      
                                                   
    public BeanListener(String Lab) 
    {                         
 	setLayout(new GridLayout(3,1));
 	add(new Label("I'm color listener"));                                                                              
 	add(new Label("I know now you are"));                                                                              
 	add(s = new TextField(Lab, 20));
   }
      
    public void propertyChange(PropertyChangeEvent evt)
    {
    	String propertyName=evt.getPropertyName();
    	if(propertyName.equalsIgnoreCase("color"))
    	{
    		String curColor="red";
    		if((Color)(evt.getNewValue())==Color.green)
    			curColor="green";
    		s.setText(curColor);
    	}
    }  
  
}                                                                  