import java.awt.*; 
import java.io.Serializable; 
import java.beans.*;
public class CustomBean extends Canvas implements Serializable 
{ 
private Color color=Color.red;
//定义受限属性
private VetoableChangeSupport vetos = new VetoableChangeSupport(this);
//Constructor sets inherited properties 
public CustomBean() 
{ 
setSize(100,100); 
setBackground(color); 
} 
public Color getColor()
{
	return color;
}
public void setColor(Color newColor) throws PropertyVetoException
{
Color oldColor = color;
//首先把变化告诉有否决权者。如果任何监听者反对，我们不捕捉例外，而是让它传递到调用者。 
vetos.fireVetoableChange("color",oldColor, newColor); 
//没有否决发生，因此变化继续下去。 
color = newColor;
	repaint();
}
    public void paint(Graphics g) 
{
	setBackground(color); 
	String tempColor="red";
	        if(color==Color.red)
		        tempColor="red";
	        else if(color==Color.green)
		        tempColor="green";
	        else if(color==Color.yellow)
		        tempColor="yellow";
	        Font f1 = new Font("Monospaced",Font.BOLD,20);
	        g.setFont(f1);
	        g.drawString(tempColor,20,60);	
}
public void addVetoableChangeListener ( VetoableChangeListener l )
{
vetos.addVetoableChangeListener ( l ); 
}
    
public void removeVetoableChangeListener ( VetoableChangeListener l )
{
vetos.removeVetoableChangeListener ( l );
}

} 
