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

public class demo03f extends Applet implements ActionListener {
  CardLayout card = new CardLayout() ;
  Color[]  cols = {Color.yellow,Color.blue,Color.magenta,
    Color.cyan,Color.pink} ;
  
  public void init() {
    int i ;
    setLayout( card ) ;
    for( i=0 ; i<5 ; i++ ) {
      add("Page"+(i+1),new myPanel("PANEL"+(i+1),cols[i],this)) ;
    }
    card.first(this) ;
  }

  public void actionPerformed(ActionEvent e) {
    if( e.getSource() instanceof Button ) {
      if( e.getActionCommand() == "Prev" ) {
        card.previous(this) ;
      }
      else {
        card.next(this) ;
      }
    }
  }

  class myPanel extends Panel {
    Button bt_next, bt_prev ;
    String panelName ;
    Color  bgColor ;
    myPanel( String name, Color bg, ActionListener p ) {
      panelName = name ;
      bgColor = bg ;
      bt_prev =new Button("Prev") ;
      bt_next =new Button("Next") ;
      add(bt_prev) ; add(bt_next) ;
      bt_prev.addActionListener(p) ;
      bt_next.addActionListener(p) ;
    }
    public void paint(Graphics g) {
      setBackground(bgColor) ;
      g.drawString("This panel is named \""+panelName+"\"",50,100) ;
    }
  }

}