コード例 #1
0
  protected JMenu buildEditMenu() {
    JMenu edit = new JMenu("Edit");
    JMenuItem undo = new JMenuItem("Undo");
    JMenuItem copy = new JMenuItem("Copy");
    JMenuItem cut = new JMenuItem("Cut");
    JMenuItem paste = new JMenuItem("Paste");
    JMenuItem prefs = new JMenuItem("Preferences...");

    undo.setEnabled(false);
    copy.setEnabled(false);
    cut.setEnabled(false);
    paste.setEnabled(false);

    prefs.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            openPrefsWindow();
          }
        });

    edit.add(undo);
    edit.addSeparator();
    edit.add(cut);
    edit.add(copy);
    edit.add(paste);
    edit.addSeparator();
    edit.add(prefs);
    return edit;
  }
コード例 #2
0
  protected JMenu buildFileMenu() {
    JMenu file = new JMenu("File");
    JMenuItem newWin = new JMenuItem("New");
    JMenuItem open = new JMenuItem("Open");
    JMenuItem quit = new JMenuItem("Quit");

    newWin.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            newDocument();
          }
        });

    open.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            openDocument();
          }
        });

    quit.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            quit();
          }
        });

    file.add(newWin);
    file.add(open);
    file.addSeparator();
    file.add(quit);
    return file;
  }