
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
//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 CardLayout2 extends JFrame {

  private JMenuBar menuBar1;
  private JMenu MainFile;
  private JMenuItem Mn1;
  private JMenuItem Mn2;
  private JMenuItem Mn3;


  int FarbpanelNr = 1;

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

  public CardLayout2() {
    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

    this.setLayout( cardLayout2 );


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

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


    setMenus();
  }  // setGUI

    // setzt die Menüs
  private void setMenus() {
    menuBar1 = new JMenuBar();

      // DATEI
    MainFile = new JMenu("CardLayout");
    Mn1 = new JMenuItem("1");
    Mn2 = new JMenuItem("2");
    Mn3 = new JMenuItem("3");


    Mn1.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        Mn1_click();
      }
    });
    MainFile.add(Mn1);

    Mn2.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        Mn2_click();
      }
    });
    MainFile.add(Mn2);


    Mn3.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        Mn3_click();
      }
    });
    MainFile.add(Mn3);
    menuBar1.add(MainFile);
    this.setJMenuBar(menuBar1);
  } // setMenus



  void Mn1_click() {
     cardLayout2.show(this.getContentPane(),"green");
  }  // Mn1

  void Mn2_click() {
     cardLayout2.show(this.getContentPane(),"red");
  }  // Mn2

  void Mn3_click() {
     cardLayout2.show(this.getContentPane(),"blue");
  }  // Mn3


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

}



class myCanvas extends Canvas {

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

  }
}

