//Titel:            Testbeispiel für MDI-Fenster
//Version:          1.0
//Copyright:        HS-Harz, FB AI
//Autor:            Dipl.-Inf. Dipl.-Ing. Michael Wilhelm
//Firma:


//Beschreibung:     Komplexes Beispiel für MDI-Steuerung
//                  MDI Beispiel mit Vererbung
//                  Es existiert eine gemeinsame Basisklasse für die internen Fenster


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

// für Opendialog
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.*;

import javax.swing.event.*;


import java.awt.Container;


public class Look_and_Feel_01 extends JFrame implements JFrameAktivateClient {
  // Container für die Clientfenster
  private JDesktopPane _desktopPane = new JDesktopPane();

    // Menü Variablen
  private JMenuBar menuBar1;
  private JMenu MainFile;
  private JMenuItem MnNew1;
  private JMenuItem MnNew2;

  private JMenuItem MnOpen;
  private JMenuItem MnClose;

  private JMenu MainEdit;
  private JMenuItem MnCut;
  private JMenuItem MnCopy;
  private JMenuItem MnInsert;

  private JMenu MainView;
  private JCheckBoxMenuItem MnStatusbar;  //  JCheckBoxMenuItem
  private JMenuItem MnReload;

  private JMenu MainLook_Feel;
  private JMenuItem MnLook_Feel_Windows;
  private JMenuItem MnLook_Feel_Motif;
  private JMenuItem MnLook_Feel_Metal;
  private JMenuItem MnLook_Feel_Macintosh;


  private JMenu MainWindows;
  private JMenuItem MnPrevWindows;
  private JMenuItem MnNextWindows;
  private JMenuItem MnTile;
  private JMenuItem MnCascade;

  private CStatusBar _statusBar;

  private MyInternalFrameInterface _actualFrame=null;

  // Variablen für die Steuerung der einzelnen Fenster
  // wenn ein Fenster mit der Maus aktiviert wurde, ruft es das
  //   Mainfenster zur Registrierung auf.
  // Idee: Befehl save muss an das aktuelle Fenster
  // JInternalFrame

   // Konstruktor
  public Look_and_Feel_01() {
    setGUI();
    this.setSize( 800, 600);
  }

  public void setGUI() {
    this.getContentPane().setLayout( new BorderLayout() );

    setToolBars();

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

    setMenus();

    _statusBar = new CStatusBar();
     this.getContentPane().add(_statusBar, BorderLayout.SOUTH);

  }  // setGUI


    // ButtonImage
  private ImageIcon loadIcon(String name, String description) {
   	// String path = "images" + name;
   	String path = name;  // Hier eventuell den path eintragen
    return new ImageIcon(path, description);
  }

  private void setToolBars() {
    JToolBar toolBar = new JToolBar();

    JButton BnOpen1 = new JButton("Öffnen (1)");
    BnOpen1.setFont( new Font("Arial", Font.BOLD,18)  );
    BnOpen1.setIcon( loadIcon("open.gif","öffnen") );

    JButton BnOpen2 = new JButton("Öffnen (2)");
    BnOpen2.setFont( new Font("Arial", Font.BOLD,18)  );
    BnOpen2.setIcon( loadIcon("open.gif","öffnen") );


    JButton BnNew = new JButton("Neu");
    BnNew.setIcon( loadIcon("new.gif","öffnen") );
    BnNew.setFont( new Font("Arial", Font.BOLD,18)  );
    toolBar.add(BnOpen1);
    BnOpen1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        MnOpen1_actionPerformed(e);  // !!!!!!
      }
    });

    toolBar.add(BnOpen2);
    BnOpen2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        MnOpen2_actionPerformed(e);  // !!!!!!
      }
    });

    BnNew.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        MnNew1_click();  // Aufruf der gemeinsamen Methode
      }
    });
    toolBar.add(BnNew);
    this.getContentPane().add(toolBar, BorderLayout.NORTH);
  } // setToolBars



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

      // DATEI
    MainFile = new JMenu("Datei");
    MnNew1 = new JMenuItem("Neu Typ1");
    MnNew2 = new JMenuItem("Neu Typ2");
    MnOpen = new JMenuItem("Öffnen");
    MnClose = new JMenuItem("Schließen");

    MnNew1.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnNew1_click();
      }
    });
    MnNew1.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
    MainFile.add(MnNew1);

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

    MnOpen.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnOpen1_actionPerformed(e);
      }
    });
    MnOpen.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    MainFile.add(MnOpen);
    MainFile.addSeparator();

    // --------------------------
    MnClose.addActionListener(new ActionListener()  {

      public void actionPerformed(ActionEvent e) {
        MnClose_actionPerformed(e);
      }
    });
    MainFile.add(MnClose);


    menuBar1.add(MainFile);

    // --------------------------------------
    
    // EDIT
    MainEdit = new JMenu("Bearbeiten");
    MnCut = new JMenuItem("Ausschneiden");
    MnCopy = new JMenuItem("Kopieren");
    MnInsert = new JMenuItem("Einfügen");

    MnCut.addActionListener(new ActionListener()  {

      public void actionPerformed(ActionEvent e) {
        MnCut_actionPerformed(e);
      }
    });
    MnCut.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
    MainEdit.add(MnCut);

    MnCopy.addActionListener(new ActionListener()  {

      public void actionPerformed(ActionEvent e) {
        MnCopy_actionPerformed(e);
      }
    });
    MnCopy.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    MainEdit.add(MnCopy);
    // MainFile.addSeparator();

    // --------------------------
    MnInsert.addActionListener(new ActionListener()  {

      public void actionPerformed(ActionEvent e) {
        MnInsert_actionPerformed(e);
      }
    });
    MnInsert.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
    MainEdit.add(MnInsert);
    menuBar1.add(MainEdit);


    // ---------------------------------------
    MainView = new JMenu("Ansicht");

    MnStatusbar = new JCheckBoxMenuItem("Statuszeile");
    //MnStatusbar.setFont( new Font("Arial", Font.BOLD,18)  );
    MainView.add(MnStatusbar);
    MnStatusbar.setSelected(true);
    
    MainView.addSeparator();

    MnReload = new JMenuItem("Aktualisieren");
    //MnReload.setFont( new Font("Arial", Font.BOLD,18)  );
    MnReload.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_F5,0));
    MainView.add(MnReload);

    menuBar1.add(MainView);

    MnReload.addActionListener(new ActionListener()  {

      public void actionPerformed(ActionEvent e) {
        MnReload_click();
      }
    });
    MnStatusbar.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnStatusbar_Click();
      }
    });
    // ---------------------------------
    
    MainLook_Feel = new JMenu("Look & Feel");
    //MainLook_Feel.setFont( new Font("Arial", Font.BOLD,18)  );

    MnLook_Feel_Windows = new JMenuItem("Windows");
    //MnLook_Feel_Windows.setFont( new Font("Arial", Font.BOLD,18)  );

    MainLook_Feel.add(MnLook_Feel_Windows);
    //MainLook_Feel.setFont( new Font("Arial", Font.BOLD,18)  );

    MnLook_Feel_Motif = new JMenuItem("Motif");
    //MnLook_Feel_Motif.setFont( new Font("Arial", Font.BOLD,18)  );
    MainLook_Feel.add(MnLook_Feel_Motif);

    MnLook_Feel_Metal = new JMenuItem("Metal");
    MainLook_Feel.add(MnLook_Feel_Metal);
    //MnLook_Feel_Metal.setFont( new Font("Arial", Font.BOLD,18)  );

    MnLook_Feel_Macintosh = new JMenuItem("Macintosh");
    //MnLook_Feel_Macintosh.setFont( new Font("Arial", Font.BOLD,18)  );
    MainLook_Feel.add(MnLook_Feel_Macintosh);

    menuBar1.add(MainLook_Feel);

    MnLook_Feel_Windows.addActionListener(new ActionListener()  {

      public void actionPerformed(ActionEvent e) {
        MnLook_and_Feel(e);
      }
    });
    MnLook_Feel_Motif.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnLook_and_Feel(e);
      }
    });
    
    MnLook_Feel_Metal.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnLook_and_Feel(e);
      }
    });
    MnLook_Feel_Macintosh.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnLook_and_Feel(e);
      }
    });
    //MnClose.setFont( new Font("Arial", Font.BOLD,18)  );
    //menuBar1.setFont( new Font("Arial", Font.BOLD,18)  );
    
    // ----------------
    // Windows
    MainWindows = new JMenu("Fenster");
    MnPrevWindows = new JMenuItem("Vorheriges Fenster");
    MnNextWindows = new JMenuItem("Nächstes Fenster");
    MnCascade = new JMenuItem("Kaskade");
    MnTile = new JMenuItem("Aufteilen");

    MnCascade.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnCascade_actionPerformed(e);
      }
    });
    MnTile.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        MnTile_actionPerformed(e);
      }
    });
    MainWindows.add(MnPrevWindows);
    MainWindows.add(MnNextWindows);
    MainWindows.addSeparator();
    MainWindows.add(MnCascade);
    MainWindows.add(MnTile);
    menuBar1.add(MainWindows);

    int m = menuBar1.getMenuCount();
    //System.out.println(m);
    for (int i=0; i<m; i++) {
      JMenu main = menuBar1.getMenu(i);
      main.setFont( new Font("Arial", Font.BOLD,18)  );
      int n = main.getItemCount();
      JMenuItem mn;
      for (int j=0; j<n; j++) {
        mn = main.getItem(j);
        // Abfrage auf Separator, sonst Absturz
        if ( mn instanceof JMenuItem )
          mn.setFont( new Font("Arial", Font.BOLD,18)  );
      }
    }

    this.setJMenuBar(menuBar1);
  } // setMenus


   // Methode fügt einen Frame ins DesktopPane
   // die Variablen width und height dienen der Positionierung
   // mit ff.length wird die Anzahl der schon existierenden Frames bestimmt
  void insertFrame(JInternalFrame frame, int nr) {
    int width, height; // Variablen für Clientfenster
    int i;
    width = _desktopPane.getWidth();
    height = _desktopPane.getHeight();
     // Array for all internal frames
    JInternalFrame[] ff = _desktopPane.getAllFrames();
    i = ff.length*20;

       // zwei Varianten
    // frame.setBounds( i, i, width-i-20, height-i-20);
    frame.setBounds( i, i, 450, 300);
    frame.setVisible(true);
    _desktopPane.add(frame, new Integer(1));
    frame.toFront();
  }  // insertFrame


    // erzeugt ein neues Fenster Frame1   DEFAULT-Einstellung
  void MnNew1_click() {
    MyInternalFrame1 frame = new MyInternalFrame1(this, null, _statusBar);
    insertFrame(frame,1);
  }

  void MnNew2_click() {
    MyInternalFrame2 frame = new MyInternalFrame2(this, "unbenannt", _statusBar);
    insertFrame(frame,2);
  }



    // öffnet eine Datei, DEFAULT-Fenster Frame4
    // eventuell auch die Extension abprüfen
  void MnOpen1_actionPerformed(ActionEvent e) {
   JFileChooser jFileChooser1 = new JFileChooser();
   String sFileName;

   jFileChooser1.setMultiSelectionEnabled(false);
   jFileChooser1.setCurrentDirectory( new File("D:\\HS-Harz\\Vorlesungen\\java\\MDI-Fenster") );

    if (JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this)) {
      // Rufen Sie openFile auf, um Text aus einer Datei in die TextArea zu laden
      sFileName = jFileChooser1.getSelectedFile().getPath();
      System.out.println(sFileName);
      MyInternalFrame1 frame = new MyInternalFrame1( this, sFileName, _statusBar );
      insertFrame(frame,4);
    }
  }  // MnOpen


   // mehrere Dateien können selektiert werden
  void MnOpen2_actionPerformed(ActionEvent e) {
   JFileChooser jFileChooser1;
   String sFileName;
   File [] files;

   // int i = jFileChooser1.showDialog(this, "Auswahl");
   jFileChooser1 = new JFileChooser();
   jFileChooser1.setMultiSelectionEnabled(true);
   jFileChooser1.setCurrentDirectory( new File("D:\\HS-Harz\\Vorlesungen\\java\\MDI-Fenster") );

    if (JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this)) {
      files = jFileChooser1.getSelectedFiles();
      int n;
      n = files.length;
      System.out.println("Anzahl der Dateien: "+n);
      for (int i=0; i<n; i++) {
      System.out.println("vor "+i);
        sFileName = files[i].getPath();
      System.out.println("nach:"+sFileName);
        MyInternalFrame2 frame = new MyInternalFrame2( this, sFileName, _statusBar );
        insertFrame(frame,4);
      }
    }
  }  // MnOpen


  void MnClose_actionPerformed(ActionEvent e) {
    System.exit(0);
  }


   // -----------------  EDIT Menü
  void MnCut_actionPerformed(ActionEvent e) {
    System.out.println("Menüeintrag Cut");
    _actualFrame.cut();
  }
  void MnCopy_actionPerformed(ActionEvent e) {
    System.out.println("Menüeintrag Copy");
    _actualFrame.copy();
  }
  void MnInsert_actionPerformed(ActionEvent e) {
    System.out.println("Menüeintrag Insert");
    _actualFrame.paste();
  }

  void MnReload_click() {
  }

  void MnStatusbar_Click() {
     _statusBar.setVisible(  MnStatusbar.isSelected()  );
  }

      public void MnLook_and_Feel(ActionEvent e) {
         try {
           if (e.getSource() ==  MnLook_Feel_Windows ) {
               UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
               SwingUtilities.updateComponentTreeUI(this.getContentPane() );
               return;
           }
           if (e.getSource() ==  MnLook_Feel_Metal ) {
               UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
              SwingUtilities.updateComponentTreeUI(this.getContentPane() );
               return;
           }
           if (e.getSource() ==  MnLook_Feel_Motif ) {
               UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
               SwingUtilities.updateComponentTreeUI(this.getContentPane() );
               return;
           }
           if (e.getSource() ==  MnLook_Feel_Macintosh ) {
               UIManager.setLookAndFeel("javax.swing.plaf.mac.MacLookAndFeel");
               SwingUtilities.updateComponentTreeUI(this.getContentPane() );
               return;
           }
         } catch (Exception exc) {
         }

    }
  

   // -----------------  Window Menü
  void MnCascade_actionPerformed(ActionEvent e) {
      int i, j, p, Abstand, w, h, n;
      JInternalFrame f;     // the actual Clientwindow
      JInternalFrame[] ff;  // Array of all internal Clientwindow
      ff = _desktopPane.getAllFrames();
      n = ff.length;  // Count of
      // calc the distace of the frames, depends on the count of the frames
      if (n > 0) {
          if (n<=3)
            Abstand = 80;
          else {
            if (n>6)
              Abstand = 25;
            else
              Abstand = 40;
          }
          // calc the width and height of each frame
          w = _desktopPane.getWidth() - (n-1)*Abstand;
          h = _desktopPane.getHeight() - (n-1)*Abstand;
          // the top frame has the index 0 !
          // index i is for the position
          // index j ist for the frames, the last is the top-frame !
          for (i = 0, j=n-1; i <n; i++,j--) {
              f = (JInternalFrame)ff[j];  // typecasting
              p = i*Abstand;
              f.setLocation(p, p);        // position
              f.setSize(w,h);             // width height
          }
      }
  }   // MnCascade_actionPerformed(ActionEvent e) {



  void MnTile_actionPerformed(ActionEvent e) {
    System.out.println("Menüeintrag Tile");
      JInternalFrame[] ff;    // Array for all internal frames
      JInternalFrame f; //
      int hoehe, anz, breite, left, top;
      int indexCol, anzCol, anzRow, anzRowUnten, n, i, h, b1, b2;
      boolean bZweiBreiten;

      ff = _desktopPane.getAllFrames();
        // Count > 0 ?
      if (ff.length > 0) {
          // Quadratische Aufteilung

            /*
             5:
                 -
                - -
                - -

             11:
                 - -
                - - -
                - - -
                - - -

            */

          n = ff.length;
          if (n < 1) {
              return;
          }
          if (n == 1) {
              f = (JInternalFrame)ff[0];
              try {
                  f.setMaximum(true);
              }
              catch (Exception e1) {
                  e1.printStackTrace();
              }
              return;
          }
          
          anzCol = (int)Math.round(Math.sqrt(n)); // Wurzel aus Anzahl
          // bestimme Anzahl der unteren (vollen) Zeilen
          anzRowUnten = n / anzCol;  // trunc
            // Abfrage nach Rest
          if (n > (anzRowUnten * anzCol)) {
              anzRow = anzRowUnten + 1;
              bZweiBreiten = true;
          }
          else {
              anzRow = anzRowUnten;
              bZweiBreiten = false;
          }
          //  AnzRow zeigt die Anzahl aller Zeilen
          
          // nun werden zwei Breiten und eine Höhe ausgerechnet
          // 1. Breite  gilt für die vollen Reihen
          // 2. Breite  gilt für oberste  Reihe, falls sie nicht voll ist
          hoehe = _desktopPane.getHeight();
          h = _desktopPane.getHeight() / anzRow;
          b1 = _desktopPane.getWidth() / anzCol; // volle Breite
          if (bZweiBreiten)
             b2 = _desktopPane.getWidth() / (n - anzCol * anzRowUnten); // untere Breite
          else
             b2 = b1;

          // Rückwärts
          anz = 0;
          left = 0;
          top = hoehe - h;
          indexCol = 0;
          for (i = ff.length - 1; i >= 0; i--) {
              f = (JInternalFrame)ff[i];
              //f.setSize(100,100);
              try {
                  f.setMaximum(false);
              }
              catch (Exception e2) {
                  e2.printStackTrace();
              }
              anz++;
              indexCol++;
              if (indexCol > anzCol) {
                  // neue Reihe anfangen
                  left = 0;
                  top -= h;
                  indexCol = 1;
              }
              // Position im Fenster setzen
              f.setLocation(left, top);
              // Breite Höhe setzen
              // Check, ob man in der obersten Zeile sich befindet ?
              if (anz > (anzRowUnten * anzCol)) {
                  f.setSize(b2, h); // width height
                  left += b2;
              }
              else {
                  f.setSize(b1, h); // width height
                  left += b1;
              }
          }
      }
  }


    // wird von aktivierten Frame aufgerufen
  public void setActualFrame(MyInternalFrameInterface Frame) {
    _actualFrame = Frame;
    setTitle(  Frame.getCaption()  );
  }

    // dient zum Beenden
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if(e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }


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

}


// --------------------------------
// Basisklasse für die Vererbung

interface JFrameAktivateClient {
  void setActualFrame( MyInternalFrameInterface frame );

}

interface MyInternalFrameInterface {
  public void cut();
  public void copy();
  public void paste();
  public void save();

  public String getCaption();
  void this_internalFrameActivated(InternalFrameEvent e);

}


abstract class MyInternalFrame0 extends JInternalFrame implements MyInternalFrameInterface {
  protected String _sFileName;
  protected String _Caption;
  protected JFrameAktivateClient _Main;

  BorderLayout borderLayout1 = new BorderLayout();

  public MyInternalFrame0(JFrameAktivateClient Main, String sFileName)  {
    _sFileName = sFileName;
    _Main = Main;
    if (sFileName==null)
      _Caption = "noname";
    else
      _Caption = sFileName;
  }


    // wird aufgerufen vom MainFenster
  public String getCaption() {
   return _Caption;
  }


  abstract void createGUI();
  abstract void initGUIFromData();

}  // Internel Frame0



class MyInternalFrame1 extends MyInternalFrame0 {
  JTextArea _editor = new JTextArea();
  String _sFileName;
  CStatusBar _statusBar;

  public MyInternalFrame1(JFrameAktivateClient Main,
              String sFileName,   CStatusBar statusBar) {
    super(Main, "FrameTyp1");   // sFileName);
    _sFileName = sFileName;
    _statusBar = statusBar;
    setGUI();
    setGUI();
    this.setTitle( getCaption() );
    setClosable(true);
    setIconifiable(true);

    setMaximizable(true);
    setResizable(true);
    setTitle( sFileName );
  }

  public void setGUI() {
    this.getContentPane().setLayout( new BorderLayout() );

    JToolBar toolBar = new JToolBar();
    JButton BnOpen = new JButton("Open");
    BnOpen.setFont( new Font("Arial", Font.BOLD,18)  );
    JButton BnNew = new JButton("New");
    BnNew.setFont( new Font("Arial", Font.BOLD,18)  );
    toolBar.add(BnOpen);
    toolBar.add(BnNew);


    this.getContentPane().add(toolBar, BorderLayout.NORTH);

    _editor.setFont( new Font("Arial", Font.BOLD,18)  );

     this.getContentPane().add(new JScrollPane(_editor), BorderLayout.CENTER);

     createGUI();
    this.setClosable(true);
    this.setIconifiable(true);

    addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() {

      public void internalFrameActivated(InternalFrameEvent e) {
        this_internalFrameActivated(e);
      }
    });

  }  // setGUI

  public void this_internalFrameActivated(InternalFrameEvent e) {
    System.out.println("setAktivate: "+_sFileName);
    _Main.setActualFrame( this );
  }

  void createGUI() {
    _editor.setText("Editor" +"\n"+
             "Quelltext:"+'\n'+
             "JToolBar toolBar = new JToolBar();" + '\n'+
             "JButton BnOpen = new JButton('Open');" + '\n'+
             "JButton BnNew = new JButton('New');" + '\n'+
             "toolBar.add(BnOpen);"+'\n'+
             "toolBar.add(BnNew);"+'\n'+
             ""
    );
  }

  void initGUIFromData() {
  }

  public void save() {
    System.out.println("save Internalframe1");
  }

  public void cut() {
      _editor.cut();
  }

  public void copy() {
    System.out.println("xxxxxxxx Menüeintrag copy");
      _editor.copy();
  }

  public void paste() {
    System.out.println("xxxxxxxx Menüeintrag Insert");
      _editor.paste();
  }

}  // InternalFrame1



class MyInternalFrame2 extends MyInternalFrame0 implements Runnable {
  JTextArea _editor = new JTextArea();
  JLabel jLabel1 = new JLabel();
  CStatusBar _statusBar;
  String _sFileName;

  public MyInternalFrame2(JFrameAktivateClient Main, String sFileName, CStatusBar statusBar) {
    super(Main, "FrameTyp2");   // sFileName);
    setGUI();
    setGUI();
    this.setTitle( sFileName );
    _statusBar = statusBar;
    _sFileName = sFileName;
    setClosable(true);
    setIconifiable(true);

    setMaximizable(true);
    setResizable(true);
    setTitle( getCaption() );
  }


  public void setGUI() {
    this.getContentPane().setLayout( new BorderLayout() );

    JToolBar toolBar = new JToolBar();
    JButton BnCalc = new JButton("Calc");
    BnCalc.setFont( new Font("Arial", Font.BOLD,18)  );
    JButton BnNew = new JButton("New");
    BnNew.setFont( new Font("Arial", Font.BOLD,18)  );
    toolBar.add(BnCalc);
    toolBar.add(BnNew);


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

      public void actionPerformed(ActionEvent e) {
        BnCalc_actionPerformed(e);  // !!!!!!
      }
    });


    this.getContentPane().add(toolBar, BorderLayout.NORTH);

    jLabel1.setText("Label 1");
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 30));
    this.getContentPane().add(jLabel1, BorderLayout.CENTER);
    addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() {

      public void internalFrameActivated(InternalFrameEvent e) {
        this_internalFrameActivated(e);
      }
    });
  } // setGUI


  public void this_internalFrameActivated(InternalFrameEvent e) {
    System.out.println("setAktivate: "+_sFileName);
    _Main.setActualFrame( this );
  }
  
  // Thread-Methode
  public void run() {
    int s=0;
    this.setTitle("Run");
    for (int i=0; i<1000; i++) {
      s=s+i;
      jLabel1.setText( Integer.toString(s) );
      jLabel1.paintImmediately(0,0, jLabel1.getWidth(), jLabel1.getHeight());
      _statusBar.setText2( Integer.toString(s) );

      try {
          Thread.sleep(10); // delay(100);
      }
      catch (InterruptedException e) {
      }
    }
    this.setTitle("Ready Run");
  }  // Run


  void BnCalc_actionPerformed(ActionEvent e) {
    Thread t;
    t = new Thread(this);
    t.start();
  }


  void createGUI() {
  }

  void initGUIFromData() {
  }


  public void save() {
    System.out.println("save Internalframe2");
  }

  public void cut() {
    _editor.cut();
  }

  public void copy() {
    _editor.copy();
  }

  public void paste() {
    System.out.println("Frame 2 Menüeintrag Insert");
      _editor.paste();
  }

}  // InternalFrame2



class CStatusBar extends JPanel {
    
    private JLabel _label1 = new JLabel(" ");

    private JLabel _label2 = new JLabel("");
    
    /** Creates a new instance of myStatusBar */
    public CStatusBar() {
        setGUI();
    }
    
    private void setGUI() {
        setLayout ( new GridBagLayout() );
        add( _label1, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, 
                new Insets(0,0,0,0), 30, 0));

        add( _label2, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0,
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, 
                new Insets(0,10,0,0), 0, 0));
        
      _label1.setFont( new Font("Arial", Font.BOLD,12)  );
      _label2.setFont( new Font("Arial", Font.BOLD,12)  );
      
      _label1.setForeground(Color.red);
      _label2.setForeground(Color.red);

    }
    
    private void setText1(String sText) {
        _label1.setText( sText);
    }

    public void setText2(String sText) {
        _label2.setText( sText);
    }
    
    public JLabel getFirstLabel() {
        return _label1;
    }
    
}


