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

//实现MouseListener，可以处理鼠标单击事件
public class BeanTest extends Applet implements MouseListener
{
	    CustomBean cBean;
	    Button b;
	    Button b1;     
	    Button b2;     
	     
    public void init() 
{
	        setLayout(new BorderLayout());
	        cBean = new CustomBean();
	        b1 = new Button("ChangeLeft");                      
        b1.addMouseListener(this);     	
	        b2 = new Button("ChangeRight");                      
        b2.addMouseListener(this);     	
        add("Center", cBean);
    	    add("North",b1);
    	    add("South",b2);     
     }

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

      public void mousePressed(MouseEvent e) 
      {
          // ChangeLeft按钮改变左半部分的颜色，在红黄之间切换
	          if(e.getSource()==b1)
	          {
if(Color.red==cBean.getColorSet(0))
                  cBean.setColorSet(0,Color.yellow);
              else if(Color.yellow==cBean.getColorSet(0))
                  cBean.setColorSet(0,Color.red);
	          }
          // ChangeRight按钮改变右半部分的颜色，在蓝绿之间切换
	          else if(e.getSource()==b2)
	          {
	              if(Color.green==cBean.getColorSet(1))
                   cBean.setColorSet(1,Color.blue);
              else if(Color.blue==cBean.getColorSet(1))
                   cBean.setColorSet(1,Color.green);
	          }
       }

      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(300, 300);
	            f.show();
      }

      public String getAppletInfo() 
{
             return "A simple bean test program.";
      }
}
