public void createPopupMenu() {
    super.createPopupMenu();

    JPopupMenu popupMenu = getPopupMenu();
    if (popupMenu == null) {
      popupMenu = new JPopupMenu();
      setPopupMenu(popupMenu);
    } else {
      popupMenu.addSeparator();
    }

    propertiesItem = new JMenuItem("Properties ...");

    propertiesItem.addActionListener(this);
    propertiesItem.setMnemonic('s');
    popupMenu.add(propertiesItem);

    popupMenu.addSeparator();
    ButtonGroup group = new ButtonGroup();
    inItem = new JRadioButtonMenuItem("IN");
    group.add(inItem);
    inItem.addActionListener(this);
    popupMenu.add(inItem);
    outItem = new JRadioButtonMenuItem("OUT");
    group.add(outItem);
    outItem.addActionListener(this);
    popupMenu.add(outItem);
    inoutItem = new JRadioButtonMenuItem("INOUT");
    group.add(inoutItem);
    inoutItem.addActionListener(this);
    popupMenu.add(inoutItem);
  }
  /** Builds the MenuBar */
  private void buildUI() {
    // Construct menu items
    JMenu lookAndFeel = new JMenu("Look and feel");
    JRadioButtonMenuItem nativeLaF = new JRadioButtonMenuItem("Native", true);
    JRadioButtonMenuItem javaLaF = new JRadioButtonMenuItem("Java (Metal)");
    JRadioButtonMenuItem motifLaF = new JRadioButtonMenuItem("Motif");
    JMenu help = new JMenu("Help");
    JMenuItem about = new JMenuItem("About");

    // Add menu items to menu bar
    add(lookAndFeel);
    lookAndFeel.add(nativeLaF);
    lookAndFeel.add(javaLaF);
    lookAndFeel.add(motifLaF);
    add(Box.createHorizontalGlue());
    add(help);
    help.add(about);

    // Add buttons to button group
    ButtonGroup laFGroup = new ButtonGroup();
    laFGroup.add(nativeLaF);
    laFGroup.add(javaLaF);
    laFGroup.add(motifLaF);

    // Set action listeners
    nativeLaF.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            UIUtilities.setLookAndFeel(owner, UIManager.getSystemLookAndFeelClassName());
            owner.pack();
          }
        });

    javaLaF.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            UIUtilities.setLookAndFeel(owner, UIManager.getCrossPlatformLookAndFeelClassName());
            owner.pack();
          }
        });

    motifLaF.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            UIUtilities.setLookAndFeel(owner, "com.sun.java.swing.plaf.motif.MotifLookAndFeel");
            owner.pack();
          }
        });

    about.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            UIUtilities.showAboutDialog(owner);
          }
        });
  }
Exemplo n.º 3
0
  /** Return a menu for DesktopWindow and add a special listener. */
  public static JMenu getCurrencyMenu(ActionListener listener) {
    JRadioButtonMenuItem menuItem;
    String defaultCurrency = Money.getCurrencyFor(Money.getDefaultCurrency());

    JMenu menu = new JMenu("Währung");
    ButtonGroup group = new ButtonGroup();

    JMenu europeanMenu = new JMenu("Europa");
    String europeanCurrencies[] = Money.getEuropeanCurrencyList();

    for (int i = 0; i < europeanCurrencies.length; i++) {
      menuItem = new RadioCurrencyMenuItem(europeanCurrencies[i]);
      menuItem.addActionListener(listener);
      europeanMenu.add(menuItem);

      group.add(menuItem);

      if (europeanCurrencies[i].startsWith(defaultCurrency)) {
        menuItem.setSelected(true);
      }

      if (i == 0) {
        europeanMenu.addSeparator();
      }
    }

    menu.add(europeanMenu);

    return menu;
  }
  protected JMenu buildSpeedMenu() {
    JMenu speed = new JMenu("Drag");

    JRadioButtonMenuItem live = new JRadioButtonMenuItem("Live");
    JRadioButtonMenuItem outline = new JRadioButtonMenuItem("Outline");

    JRadioButtonMenuItem slow = new JRadioButtonMenuItem("Old and Slow");

    ButtonGroup group = new ButtonGroup();

    group.add(live);
    group.add(outline);
    group.add(slow);

    live.setSelected(true);

    slow.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            // for right now I'm saying if you set the mode
            // to something other than a specified mode
            // it will revert to the old way
            // This is mostly for comparison's sake
            desktop.setDragMode(-1);
          }
        });

    live.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            desktop.setDragMode(JDesktopPane.LIVE_DRAG_MODE);
          }
        });

    outline.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
          }
        });

    speed.add(live);
    speed.add(outline);
    speed.add(slow);
    return speed;
  }
Exemplo n.º 5
0
 public TreeElementMenu(
     MainFrame _frame,
     TopiaryWindow _parent,
     String name,
     ColorPanel _colorPanel,
     int elementType) {
   super(name);
   parent = _parent;
   frame = _frame;
   tree = ((TreeWindow) parent).tree;
   noColoringMenuItem.addActionListener(this);
   add(noColoringMenuItem);
   majorityColoringMenuItem.addActionListener(this);
   add(majorityColoringMenuItem);
   colorBy = new ColorByMenu(frame, parent, _colorPanel, elementType);
   add(colorBy);
 }
Exemplo n.º 6
0
 private ButtonGroup createButtonGroup() {
   ButtonGroup g1 = new ButtonGroup();
   for (int j = 0; j < 4; j++)
     for (int i = 0; i < 16; i++) {
       JRadioButtonMenuItem b = new JRadioButtonMenuItem(new PopupIcon(i + 16 * j));
       b.setSelectedIcon(null);
       b.addActionListener(this::doSelect);
       this.add(b);
       g1.add(b);
     }
   return g1;
 }
Exemplo n.º 7
0
  /** Creates a JRadioButtonMenuItem for the Themes menu */
  private JMenuItem createThemesMenuItem(
      JMenu menu,
      String label,
      char mnemonic,
      String accessibleDescription,
      DefaultMetalTheme theme) {
    JRadioButtonMenuItem mi = (JRadioButtonMenuItem) menu.add(new JRadioButtonMenuItem(label));
    themesMenuGroup.add(mi);
    mi.setMnemonic(mnemonic);
    mi.getAccessibleContext().setAccessibleDescription(accessibleDescription);
    mi.addActionListener(new ChangeThemeAction(this, theme));

    return mi;
  }
  /** Adds the menu items to the menuber. */
  protected void arrangeMenu() {

    // Build the first menu.
    fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);

    viewMenu = new JMenu("View");
    viewMenu.setMnemonic(KeyEvent.VK_V);
    menuBar.add(viewMenu);

    runMenu = new JMenu("Run");
    runMenu.setMnemonic(KeyEvent.VK_R);
    menuBar.add(runMenu);

    // Build the second menu.
    helpMenu = new JMenu("Help");
    helpMenu.setMnemonic(KeyEvent.VK_H);
    menuBar.add(helpMenu);

    programMenuItem = new JMenuItem("Load Program", KeyEvent.VK_O);
    programMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            programMenuItem_actionPerformed();
          }
        });
    fileMenu.add(programMenuItem);

    scriptMenuItem = new JMenuItem("Load Script", KeyEvent.VK_P);
    scriptMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            scriptMenuItem_actionPerformed();
          }
        });
    fileMenu.add(scriptMenuItem);
    fileMenu.addSeparator();

    exitMenuItem = new JMenuItem("Exit", KeyEvent.VK_X);
    exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.ALT_MASK));
    exitMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            exitMenuItem_actionPerformed();
          }
        });
    fileMenu.add(exitMenuItem);

    viewMenu.addSeparator();

    ButtonGroup animationRadioButtons = new ButtonGroup();

    animationSubMenu = new JMenu("Animate");
    animationSubMenu.setMnemonic(KeyEvent.VK_A);
    viewMenu.add(animationSubMenu);

    partAnimMenuItem = new JRadioButtonMenuItem("Program flow");
    partAnimMenuItem.setMnemonic(KeyEvent.VK_P);
    partAnimMenuItem.setSelected(true);
    partAnimMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            partAnimMenuItem_actionPerformed();
          }
        });
    animationRadioButtons.add(partAnimMenuItem);
    animationSubMenu.add(partAnimMenuItem);

    fullAnimMenuItem = new JRadioButtonMenuItem("Program & data flow");
    fullAnimMenuItem.setMnemonic(KeyEvent.VK_D);
    fullAnimMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fullAnimMenuItem_actionPerformed();
          }
        });
    animationRadioButtons.add(fullAnimMenuItem);
    animationSubMenu.add(fullAnimMenuItem);

    noAnimMenuItem = new JRadioButtonMenuItem("No Animation");
    noAnimMenuItem.setMnemonic(KeyEvent.VK_N);
    noAnimMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            noAnimMenuItem_actionPerformed();
          }
        });
    animationRadioButtons.add(noAnimMenuItem);
    animationSubMenu.add(noAnimMenuItem);

    ButtonGroup additionalDisplayRadioButtons = new ButtonGroup();

    additionalDisplaySubMenu = new JMenu("View");
    additionalDisplaySubMenu.setMnemonic(KeyEvent.VK_V);
    viewMenu.add(additionalDisplaySubMenu);

    scriptDisplayMenuItem = new JRadioButtonMenuItem("Script");
    scriptDisplayMenuItem.setMnemonic(KeyEvent.VK_S);
    scriptDisplayMenuItem.setSelected(true);
    scriptDisplayMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            scriptDisplayMenuItem_actionPerformed();
          }
        });
    additionalDisplayRadioButtons.add(scriptDisplayMenuItem);
    additionalDisplaySubMenu.add(scriptDisplayMenuItem);

    outputMenuItem = new JRadioButtonMenuItem("Output");
    outputMenuItem.setMnemonic(KeyEvent.VK_O);
    outputMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            outputMenuItem_actionPerformed();
          }
        });
    additionalDisplayRadioButtons.add(outputMenuItem);
    additionalDisplaySubMenu.add(outputMenuItem);

    compareMenuItem = new JRadioButtonMenuItem("Compare");
    compareMenuItem.setMnemonic(KeyEvent.VK_C);
    compareMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            compareMenuItem_actionPerformed();
          }
        });
    additionalDisplayRadioButtons.add(compareMenuItem);
    additionalDisplaySubMenu.add(compareMenuItem);

    noAdditionalDisplayMenuItem = new JRadioButtonMenuItem("Screen");
    noAdditionalDisplayMenuItem.setMnemonic(KeyEvent.VK_N);
    noAdditionalDisplayMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            noAdditionalDisplayMenuItem_actionPerformed();
          }
        });
    additionalDisplayRadioButtons.add(noAdditionalDisplayMenuItem);
    additionalDisplaySubMenu.add(noAdditionalDisplayMenuItem);

    ButtonGroup formatRadioButtons = new ButtonGroup();

    numericFormatSubMenu = new JMenu("Format");
    numericFormatSubMenu.setMnemonic(KeyEvent.VK_F);
    viewMenu.add(numericFormatSubMenu);

    decMenuItem = new JRadioButtonMenuItem("Decimal");
    decMenuItem.setMnemonic(KeyEvent.VK_D);
    decMenuItem.setSelected(true);
    decMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            decMenuItem_actionPerformed();
          }
        });
    formatRadioButtons.add(decMenuItem);
    numericFormatSubMenu.add(decMenuItem);

    hexaMenuItem = new JRadioButtonMenuItem("Hexadecimal");
    hexaMenuItem.setMnemonic(KeyEvent.VK_H);
    hexaMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            hexaMenuItem_actionPerformed();
          }
        });
    formatRadioButtons.add(hexaMenuItem);
    numericFormatSubMenu.add(hexaMenuItem);

    binMenuItem = new JRadioButtonMenuItem("Binary");
    binMenuItem.setMnemonic(KeyEvent.VK_B);
    binMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            binMenuItem_actionPerformed();
          }
        });
    formatRadioButtons.add(binMenuItem);
    numericFormatSubMenu.add(binMenuItem);

    viewMenu.addSeparator();

    singleStepMenuItem = new JMenuItem("Single Step", KeyEvent.VK_S);
    singleStepMenuItem.setAccelerator(KeyStroke.getKeyStroke("F11"));
    singleStepMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            singleStepMenuItem_actionPerformed();
          }
        });
    runMenu.add(singleStepMenuItem);

    ffwdMenuItem = new JMenuItem("Run", KeyEvent.VK_F);
    ffwdMenuItem.setAccelerator(KeyStroke.getKeyStroke("F5"));
    ffwdMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            ffwdMenuItem_actionPerformed();
          }
        });
    runMenu.add(ffwdMenuItem);

    stopMenuItem = new JMenuItem("Stop", KeyEvent.VK_T);
    stopMenuItem.setAccelerator(KeyStroke.getKeyStroke("shift F5"));
    stopMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            stopMenuItem_actionPerformed();
          }
        });
    runMenu.add(stopMenuItem);

    rewindMenuItem = new JMenuItem("Reset", KeyEvent.VK_R);
    rewindMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            rewindMenuItem_actionPerformed();
          }
        });
    runMenu.add(rewindMenuItem);

    runMenu.addSeparator();

    breakpointsMenuItem = new JMenuItem("Breakpoints", KeyEvent.VK_B);
    breakpointsMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            breakpointsMenuItem_actionPerformed();
          }
        });
    runMenu.add(breakpointsMenuItem);

    profilerMenuItem = new JMenuItem("Profiler", KeyEvent.VK_I);
    profilerMenuItem.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            showProfiler();
          }
        });
    profilerMenuItem.setEnabled(false);
    runMenu.add(profilerMenuItem);

    usageMenuItem = new JMenuItem("Usage", KeyEvent.VK_U);
    usageMenuItem.setAccelerator(KeyStroke.getKeyStroke("F1"));
    usageMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            usageMenuItem_actionPerformed();
          }
        });
    helpMenu.add(usageMenuItem);

    aboutMenuItem = new JMenuItem("About ...", KeyEvent.VK_A);
    aboutMenuItem.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            aboutMenuItem_actionPerformed();
          }
        });
    helpMenu.add(aboutMenuItem);
  }
Exemplo n.º 9
0
  private void setUpMenuBar() {
    // Set Up Menu Bar
    JMenuBar menu = new JMenuBar();

    // Game Menu
    JMenu gameMenu = new JMenu("Game");
    menu.add(gameMenu);

    JMenuItem newRandom = new JMenuItem("New Game");
    gameMenu.add(newRandom);
    newRandom.setAccelerator(
        KeyStroke.getKeyStroke(
            KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    newRandom.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            newGame();
          }
        });

    gameMenu.addSeparator();

    ButtonGroup bg = new ButtonGroup();
    JRadioButtonMenuItem size4 = new JRadioButtonMenuItem("4x4 board");
    size4.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            myBoardSize = 4;
          }
        });
    size4.setSelected(true);
    bg.add(size4);
    gameMenu.add(size4);
    JRadioButtonMenuItem size5 = new JRadioButtonMenuItem("5x5 board");
    size5.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            myBoardSize = 5;
          }
        });
    bg.add(size5);
    gameMenu.add(size5);
    gameMenu.addSeparator();

    JMenuItem gameTime = new JMenuItem("Time (secs)");
    gameMenu.add(gameTime);
    gameTime.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String secs = JOptionPane.showInputDialog(BoggleGUI.this, "time in seconds");
            try {
              int len = Integer.parseInt(secs);
              myGameLength = len;
              myProgress.setMaximum(myGameLength);
            } catch (NumberFormatException e1) {
              if (secs != null) {
                showError(secs + " not valid integer value");
              }
            }
          }
        });
    gameMenu.addSeparator();
    JMenuItem quitGame = new JMenuItem("Quit");
    gameMenu.add(quitGame);
    quitGame.setMnemonic('Q');
    quitGame.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    // Help menu
    JMenu helpMenu = new JMenu("Help");
    menu.add(helpMenu);
    helpMenu.setMnemonic(KeyEvent.VK_H);

    JMenuItem aboutGame = new JMenuItem("About...");
    helpMenu.add(aboutGame);
    aboutGame.setMnemonic(KeyEvent.VK_A);
    aboutGame.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(
                BoggleGUI.this,
                "Compsci Boggle, brought to you\n"
                    + "by educators and students\n"
                    + "including, of course, you.",
                "About Game",
                JOptionPane.PLAIN_MESSAGE);
          }
        });
    setJMenuBar(menu);
  }
Exemplo n.º 10
0
  public PuzzelHA() {

    window = new JFrame("PuzzelHA");
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // window.setSize(800, 600);

    // -----------------Menü erstellen---------------------------------------
    JMenuBar menu = new JMenuBar();
    menu.setBorder(new LineBorder(Color.BLACK, 1));

    JMenu spiel = new JMenu("Spiel");
    JMenuItem reset = new JMenuItem("Reset");
    reset.addActionListener(this);
    reset.setActionCommand("reset");
    spiel.add(reset);

    JMenu ansicht = new JMenu("Ansicht");
    JMenu bild = new JMenu("BildNr.");
    ansicht.add(bild);
    ButtonGroup bg1 = new ButtonGroup();

    for (int j = 1; j <= bilder.size(); j++) {
      JRadioButtonMenuItem bn = new JRadioButtonMenuItem("" + j);
      bn.setName("" + j);
      bn.setActionCommand("b");
      bn.addActionListener(this);
      bg1.add(bn);
      bild.add(bn);
    }

    // --------------RadioButtons für Puzzelgröße----------------------------------
    JMenu pg = new JMenu("Puzzelgröße");
    ansicht.add(pg);
    ButtonGroup bg2 = new ButtonGroup();
    JRadioButtonMenuItem pgb1 = new JRadioButtonMenuItem("2x3");
    pgb1.setActionCommand("g1");
    pgb1.addActionListener(this);
    bg2.add(pgb1);
    pg.add(pgb1);

    for (int i = 2; i <= 4; i++) {
      JRadioButtonMenuItem pgb = new JRadioButtonMenuItem("" + (i * 2) + "x" + (i * 2 - 1));
      pgb.setActionCommand("g" + i);
      pgb.addActionListener(this);
      bg2.add(pgb);
      pg.add(pgb);
    }

    JMenu help = new JMenu("?");
    JMenuItem info = new JMenuItem("Info");
    info.addActionListener(this);
    info.setActionCommand("?");
    help.add(info);

    menu.add(spiel);
    menu.add(ansicht);
    menu.add(help);
    window.add(menu);
    window.setJMenuBar(menu);

    // ---------------- Menü END-------------------------------------

    baueButton();

    window.setResizable(false);
    window.setLocationRelativeTo(null);
    window.pack();
    window.setVisible(true);
  }