// einfaches Beispiel eines Internal Frame
// wird einfügt in desktopPane

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


public class MDI01 extends JFrame {

  private JDesktopPane desktopPane = new JDesktopPane();

  JMenuItem mnNew = new JMenuItem("Neue Datei");
  JMenuItem mnOpen = new JMenuItem("Öffnen");
  JMenuItem mnClose = new JMenuItem("Schließen");

  public MDI01() {
    this.setSize(new Dimension(600, 400));
    setTitle("MDI: 1. Beispiel");
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
    this.setVisible(true);
  }

  public void setGUI() {
    this.getContentPane().setLayout( new BorderLayout() );
    this.setContentPane(desktopPane); //, BorderLayout.CENTER);
    //desktopPane.setBackground(Color.black);

    setMenus();
  }

  private  void setMenus() {
    JMenuBar menuBar1 = new JMenuBar();
    JMenu mainFile = new JMenu("Datei");

    // Menü Datei
    mnNew.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        mnNew_actionPerformed(e);
      }
    });
    mainFile.add(mnNew);

    mnOpen.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        mnOpen_actionPerformed(e);
      }
    });
    mainFile.add(mnOpen);
    mainFile.addSeparator();

    // --------------------------
    mnClose.addActionListener(new ActionListener()  {
      public void actionPerformed(ActionEvent e) {
        mnClose_actionPerformed(e);
      }
    });
    mainFile.add(mnClose);
    menuBar1.add(mainFile);

    this.setJMenuBar(menuBar1);

    for (int i = 0; i < menuBar1.getComponentCount(); i++) {
      JMenu main = (JMenu) menuBar1.getComponent(i);
      main.setFont(new Font("Arial", Font.BOLD, 18));
      for (int j = 0; j < main.getItemCount(); j++) {
        Component c = main.getItem(j);
        if (c instanceof JMenuItem) {
          JMenuItem mn = (JMenuItem) c;
          mn.setFont(new Font("Arial", Font.BOLD, 18));
        }
      }
    }
  } // setMenus


  void mnNew_actionPerformed(ActionEvent e) {
    MyInternalFrame frame = new MyInternalFrame();
    frame.setBounds(0, 0, 450, 300);
    desktopPane.add(frame);
    desktopPane.moveToFront(frame);
    //frame.setMaximum2();
  }

  void mnOpen_actionPerformed(ActionEvent e) {
    MyInternalFrame frame = new MyInternalFrame();
    frame.setBounds(0, 0, 450, 300);
    desktopPane.add(frame);
    desktopPane.moveToFront(frame);
  }

  void mnClose_actionPerformed(ActionEvent e) {
    this.dispose();
  }


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



}  // mdi01



class MyInternalFrame extends JInternalFrame {
  public MyInternalFrame() {
    setGUI();
    this.setVisible(true); // wichtig ab JDK 1,5
  }

  public void setGUI() {
    this.setClosable(true);
    this.setIconifiable(true);
    this.setMaximizable(false);
    this.setResizable(false);

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

  public void setMaximum2() {
    try {
      this.setMaximum(true);
    }
    catch(java.beans.PropertyVetoException e) {
    }

  }

}

