//Titel:            Testbeispiel für ein Menü
//Version:          2.1
//Copyright:        HS-Harz, FB AI, 2007, 2010
//Autor:            Dipl.-Inf. Dipl.-Ing. Michael Wilhelm
//Firma:



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


public class menu1 extends JFrame  {

    // Menü Variablen
  private JMenuBar menuBar1;
  private JMenu MainFile;
  private JMenuItem MnNew;
  private JMenuItem MnOpen;
  private JMenuItem MnClose;



  // Konstruktor
  public menu1() {
    this.setSize( 800, 600);
    this.setVisible(true);
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    setGUI();
    setMenus();
  }

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


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

      // DATEI
    MainFile = new JMenu("Datei");
    MnNew = new JMenuItem("Neu");
    MnOpen = new JMenuItem("Öffnen");

    MnClose = new JMenuItem("Schließen");


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


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

    menuBar1.add(MainFile);

    MainFile.addSeparator();

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

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

    this.setJMenuBar(menuBar1);
  } // setMenus


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


    // erzeugt ein neues Fenster Frame1   DEFAULT-Einstellung
  void MnNew_click() {
   System.out.println("in New");
  }


  void MnOpen_actionPerformed(ActionEvent e) {
   System.out.println("in Open");
  }  // MnOpen


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

}









