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

// Einfaches JTabbedPane mit Farbpaletten und zusätzlichen Dialogfenstern

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

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

// Registerdarstellung in java
public class JTabbedPane02 extends JFrame {


  public JTabbedPane02() {
    setSize(700, 600);
    setTitle("JTabbedPane 2. Beispiel");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

    setGUI();
  }

  private void setGUI() {
      // Definition des JTabbedPane
   JTabbedPane jTabbedPane1 = new JTabbedPane(JTabbedPane.TOP);
   jTabbedPane1.setFont( new Font("Arial", Font.BOLD,32));

   jTabbedPane1.setTabPlacement(JTabbedPane.BOTTOM);


    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);
    myCanvas mc4 = new myCanvas(Color.cyan);


    ImageIcon image1 = new ImageIcon("openFile.gif");
    ImageIcon image2 = new ImageIcon("closeFile.gif");

    jTabbedPane1.addTab("grün", image1, mc1, "tip1");
    jTabbedPane1.addTab("rot", image2, mc2, "tip2");
    jTabbedPane1.add("blau",mc3);
    jTabbedPane1.add("cyan" ,mc4);



    	// Erweiterer Karten
 	jTabbedPane1.addTab("Schalter", null, createPanel1() );
  	jTabbedPane1.addTab("Liste", null, createListe() );

     jTabbedPane1.setSelectedIndex(2);
//
      // ChangeListener erzeugen
    jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        jTabbedPane1_stateChanged(e); // Aufruf Methode
      }
    });



     // Schalter definieren
    JButton BnOk = new JButton("    Ok    ");
    JButton BnEsc = new JButton("Abbruch");
    BnOk.setFont( new Font("Arial", Font.BOLD,32));
    BnEsc.setFont( new Font("Arial", Font.BOLD,32));

    JPanel pnSouth = new JPanel();
    pnSouth.setLayout(  new FlowLayout() );
    pnSouth.add(BnOk);
    pnSouth.add(BnEsc);


    this.getContentPane().add(pnSouth, BorderLayout.SOUTH );

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


  }  // jbInit





 JPanel createPanel1() {
     JButton bn1;
     JButton bn2;
     JButton bn3;
     JPanel panel;

    panel = new JPanel();
    panel.setLayout ( new FlowLayout() );
    bn1 = new JButton("1. Text");  // Label erzeugen
    panel.add(bn1,"South");
    bn2 = new JButton("2. Text");  // Label erzeugen
    panel.add(bn2,"South");
    bn3 = new JButton("3. Text");  // Label erzeugen
    panel.add(bn3,"South");
    return panel;

} // createPanel1



JPanel createListe() {
    JList liste;
    JPanel panel;

    JScrollPane scroll;
    String[] items;

    panel = new JPanel();
    panel.setLayout ( new BorderLayout() );

    items = new String[20];
    for (int i=0; i<20; i++) {
      items[i] = Integer.toHexString(i+1)+" Auswahl";
    }

    liste = new JList(items);
       // Geniere eine Scrollbox, Inhalt Liste
    scroll = new JScrollPane(liste);
    panel.add(scroll, BorderLayout.CENTER);
    return panel;
}  // createListe



  void jTabbedPane1_stateChanged(ChangeEvent e) {
     // TabbedPane refenzieren
   JTabbedPane tab = (JTabbedPane) e.getSource();
   int index = tab.getSelectedIndex();
   Component currentPage = tab.getComponentAt(index);

   System.out.println("stateChange:     Index: "+index);

  }


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



}  // JTabbedPane02


class myCanvas extends Canvas {

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

  }
}


