
//Titel:        Layout
//Version:
//Copyright:    Copyright (c) 1999
//Autor:       Ihr Name
//Organisation:      Ihre Organisation
//Beschreibung:  Ihre Beschreibung


// Beispiel mit cardLayout


import java.awt.*;
import javax.swing.*;

import java.awt.event.*;


public class CardLayout1 extends JFrame {


  JPanel pMain = new JPanel();

  int FarbpanelNr = 1;

   // CardLayout muss global sein
   // wird in der onClick Methode verwendet
  CardLayout cardLayout1 = new CardLayout(10,10);

  public CardLayout1() {
    setSize(400, 200);
    setTitle("CardLayout 1. Beispiel");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
  }

  private void setGUI() {
      // Definition des Card-Layouts und einfügen in pMain

    pMain.setLayout( cardLayout1 );

    this.getContentPane().setLayout( new BorderLayout() );

      // 2.	Definition der Farbpanels
    myCanvas mc1 = new myCanvas(Color.green);
    myCanvas mc2 = new myCanvas(Color.red);
    myCanvas mc3 = new myCanvas(Color.blue);

    pMain.add("red",mc2);
    pMain.add("blue",mc3);
    pMain.add("green", mc1 );

     // Schalter definieren
    JButton Bn = new JButton("Next");

    Bn.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        Bn_actionPerformed(e);
      }
    });
    this.getContentPane().add(Bn, 
               BorderLayout.SOUTH );

    this.getContentPane().add(pMain, 
               BorderLayout.CENTER);


  }  // setGUI


  public static void main(String[] args) {
    CardLayout1 frame = new CardLayout1();
    frame.setVisible(true);
 }


    // setzen der "Seite"
  void Bn_actionPerformed(ActionEvent e) {
    FarbpanelNr++;
    if (FarbpanelNr>=4) FarbpanelNr=1;

     switch (FarbpanelNr){
        case 1  : cardLayout1.show(pMain,"green");
								System.out.println("green" );
                  break;
        case 2  : cardLayout1.show(pMain,"red");
								System.out.println("red" );
                  break;
        case 3  : cardLayout1.show(pMain,"blue");
								System.out.println("blue" );
                  break;
        default : break;
     }
     System.out.println(cardLayout1.toString() );
  }  // Bn_actionPerformed

}



class myCanvas extends Canvas {

  public myCanvas(Color c) {
    setBackground(c);

  }
}

