예제 #1
0
  /**
   * Add the menus into the menu bar
   *
   * @param menuBar The menu bar
   */
  public void initMenuBar(JMenuBar menuBar) {
    stationModelMenu = new JMenu("Layout Models");
    stationModelMenu.addMenuListener(
        new MenuListener() {
          public void menuCanceled(MenuEvent e) {}

          public void menuDeselected(MenuEvent e) {}

          public void menuSelected(MenuEvent e) {
            makeStationModelMenu();
          }
        });

    fileMenu = new JMenu("File");
    fileMenu.addMenuListener(
        new MenuListener() {
          public void menuCanceled(MenuEvent e) {}

          public void menuDeselected(MenuEvent e) {}

          public void menuSelected(MenuEvent e) {
            makeFileMenu();
          }
        });

    menuBar.add(fileMenu);
    super.initMenuBar(menuBar);

    menuBar.add(stationModelMenu);

    JMenu helpMenu = new JMenu("Help");
    JMenuItem helpMenuItem = new JMenuItem("Layout Models");
    helpMenu.add(helpMenuItem);
    helpMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            showHelp();
          }
        });

    menuBar.add(helpMenu);
  }
예제 #2
0
  public DialogStammdaten(JFrame fenster, String[][] datensatz1, String s, Methoden datenbank1) {
    super(fenster, true);
    datenbank = datenbank1;
    datensatz = datensatz1;
    p = new JPanel();
    platzhalter = new JLabel();
    text1 = new JLabel("Name");
    text2 = new JLabel("Personalnummer");
    text3 = new JLabel("Titel");
    text4 = new JLabel("Institut");
    feld = new JComboBox();
    textName = new JTextField();
    textPersonalnr = new JTextField();
    textInstitut = new JTextField();
    textTitel = new JTextField();
    menue = new JMenuBar();
    datei = new JMenu("Datei");
    aendern = new JMenuItem("Aendern");
    hinzufuegen = new JMenuItem("Hinzufuegen");
    loeschen = new JMenuItem("Loeschen");
    beenden = new JMenuItem("Beenden");
    final JDialog dialog = this;
    this.setTitle(s);
    feld = new JComboBox(ersteElemente(datensatz));
    textName.setText(datensatz[0][0]);
    textPersonalnr.setText(datensatz[0][1]);
    setzen(datensatz, feld.getSelectedIndex());

    feld.addItemListener(
        new ItemListener() {
          public void itemStateChanged(ItemEvent e) {
            if (e.getID() == ItemEvent.ITEM_STATE_CHANGED
                && e.getStateChange() == ItemEvent.SELECTED) {
              textName.setText((String) e.getItem());
              textPersonalnr.setText(datensatz[feld.getSelectedIndex()][1]);
              setzen(datensatz, feld.getSelectedIndex());
            }
          }
        });

    datei.addMenuListener(
        new MenuListener() {
          public void menuSelected(MenuEvent e) {
            hinzufuegen.setEnabled(false);
            aendern.setEnabled(false);
            loeschen.setEnabled(false);

            if (!geaendert(datensatz, feld.getSelectedIndex())) {
              loeschen.setEnabled(true);
            } else if (!(textName.getText().equals("") || textPersonalnr.getText().equals(""))) {
              hinzufuegen.setEnabled(true);
              aendern.setEnabled(true);
            }
          }

          public void menuDeselected(MenuEvent e) {}

          public void menuCanceled(MenuEvent e) {}
        });

    hinzufuegen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String[] daten = erstellen();
            if (hinzufuegen(daten)) {
              dispose();
            } else {
              JOptionPane.showMessageDialog(
                  dialog, "Hinzufuegen geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE);
            }
          }
        });
    aendern.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String[] daten = erstellen();
            if (aendern(datensatz[feld.getSelectedIndex()][1], daten)) {
              dispose();
            } else {
              JOptionPane.showMessageDialog(
                  dialog, "Aendern geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE);
            }
          }
        });
    loeschen.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String[] daten = erstellen();
            if (loeschen(datensatz[feld.getSelectedIndex()][1])) {
              dispose();
            } else {
              JOptionPane.showMessageDialog(
                  dialog, "Loeschen geht nicht.", "Fehler", JOptionPane.ERROR_MESSAGE);
            }
          }
        });
    beenden.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            dispose();
          }
        });

    datei.add(hinzufuegen);
    datei.add(aendern);
    datei.add(loeschen);
    datei.add(beenden);
    menue.add(datei);
    this.setJMenuBar(menue);

    p.setLayout(new GridLayout(2, 5));
    p.add(platzhalter);
    p.add(text1);
    p.add(text2);
    p.add(text3);
    p.add(text4);
    p.add(feld);
    p.add(textName);
    p.add(textPersonalnr);
    p.add(textTitel);
    p.add(textInstitut);
    this.setContentPane(p);

    this.pack();
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  }