/** Method to create the menu bar, menus, and menu items */
  private void setUpMenuBar() {
    // create menu
    menuBar = new JMenuBar();
    zoomMenu = new JMenu("Zoom");
    twentyFive = new JMenuItem("25%");
    fifty = new JMenuItem("50%");
    seventyFive = new JMenuItem("75%");
    hundred = new JMenuItem("100%");
    hundred.setEnabled(false);
    hundredFifty = new JMenuItem("150%");
    twoHundred = new JMenuItem("200%");
    fiveHundred = new JMenuItem("500%");

    // add the action listeners
    twentyFive.addActionListener(this);
    fifty.addActionListener(this);
    seventyFive.addActionListener(this);
    hundred.addActionListener(this);
    hundredFifty.addActionListener(this);
    twoHundred.addActionListener(this);
    fiveHundred.addActionListener(this);

    // add the menu items to the menus
    zoomMenu.add(twentyFive);
    zoomMenu.add(fifty);
    zoomMenu.add(seventyFive);
    zoomMenu.add(hundred);
    zoomMenu.add(hundredFifty);
    zoomMenu.add(twoHundred);
    zoomMenu.add(fiveHundred);
    menuBar.add(zoomMenu);

    // set the menu bar to this menu
    pictureFrame.setJMenuBar(menuBar);
  }
예제 #2
0
파일: JImage.java 프로젝트: RussTedrake/lcm
  void initControls() {
    JMenuItem jmi;

    jmi = new JMenuItem("JImage Menu");
    jmi.setEnabled(false);
    popupMenu.add(jmi);

    jmi = new JMenuItem("Fit");
    jmi.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            fit = true;
            repaint();
          }
        });
    popupMenu.add(jmi);

    JMenu scaleMenu = new JMenu("Set Scale");
    popupMenu.add(scaleMenu);
    int scales[] = new int[] {25, 50, 100, 200, 400, 800};

    for (int i = 0; i < scales.length; i++) {
      jmi = new JMenuItem(scales[i] + " %");
      jmi.addActionListener(new ScaleAction(scales[i]));
      scaleMenu.add(jmi);
    }

    MyListener l = new MyListener();
    addMouseMotionListener(l);
    addMouseListener(l);
    addMouseWheelListener(l);
    addKeyListener(l);
  }
 /** Method to enable all menu commands */
 private void enableZoomItems() {
   twentyFive.setEnabled(true);
   fifty.setEnabled(true);
   seventyFive.setEnabled(true);
   hundred.setEnabled(true);
   hundredFifty.setEnabled(true);
   twoHundred.setEnabled(true);
   fiveHundred.setEnabled(true);
 }
  /**
   * Controls the zoom menu bar
   *
   * @param a the ActionEvent
   */
  public void actionPerformed(ActionEvent a) {

    if (a.getActionCommand().equals("Update")) {
      this.repaint();
    }

    if (a.getActionCommand().equals("25%")) {
      this.zoom(.25);
      enableZoomItems();
      twentyFive.setEnabled(false);
    }

    if (a.getActionCommand().equals("50%")) {
      this.zoom(.50);
      enableZoomItems();
      fifty.setEnabled(false);
    }

    if (a.getActionCommand().equals("75%")) {
      this.zoom(.75);
      enableZoomItems();
      seventyFive.setEnabled(false);
    }

    if (a.getActionCommand().equals("100%")) {
      this.zoom(1.0);
      enableZoomItems();
      hundred.setEnabled(false);
    }

    if (a.getActionCommand().equals("150%")) {
      this.zoom(1.5);
      enableZoomItems();
      hundredFifty.setEnabled(false);
    }

    if (a.getActionCommand().equals("200%")) {
      this.zoom(2.0);
      enableZoomItems();
      twoHundred.setEnabled(false);
    }

    if (a.getActionCommand().equals("500%")) {
      this.zoom(5.0);
      enableZoomItems();
      fiveHundred.setEnabled(false);
    }
  }