/*ch0604.java*/
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class ch0604 extends Applet implements ActionListener
{
  static Panel pn1=new Panel( );
  static CardLayout crd=new CardLayout(20,15);
  Cvs cvs[ ]=new Cvs[10];
  Button button1=new Button("第一幅");
  Button button2=new Button("下一幅");
  Button button3=new Button("上一幅");
  Button button4=new Button("第末幅");
  public void actionPerformed(ActionEvent e)
  {
    if(e.getSource()==button1)
    {
      crd.first(pn1);
    }
    else if(e.getSource()==button2)
    {
      crd.next(pn1);
    }
    else if(e.getSource()==button3)
    {
      crd.previous(pn1);
    }
    else if(e.getSource()==button4)
    {
      crd.last(pn1);
    }
  }
  class Cvs extends Canvas
  {
    int i;
    Cvs(int j)
    {
      i=j;
      setBackground(Color.yellow);
    }
    public void paint(Graphics g)
    {
      g.setColor(Color.red);
      g.fillRect(30,25,10+10*i,8+8*i);
      g.drawString("这是第"+(i+1)+"个画面",20,150);
    }
  }
  public void init( )
  {
    setSize(300,250);
    setBackground(Color.green);
    setVisible(true);
    setLayout(null);
    pn1.setLayout(crd);
    pn1.setBounds(0,40,200,190);
    pn1.setBackground(Color.blue);
    add(pn1);
    for(int k=0; k<9;k++)
    {
      cvs[k]=new Cvs(k);
      pn1.add(""+k,cvs[k]);
    }
    add(button1);
    add(button2);
    add(button3);
    add(button4);
    button1.setBounds(230,60,50,30);
    button2.setBounds(230,100,50,30);
    button3.setBounds(230,140,50,30);
    button4.setBounds(230,180,50,30);
    button1.addActionListener(this);
    button2.addActionListener(this);
    button3.addActionListener(this);
    button4.addActionListener(this);
    crd.first(pn1);
  }
}