コード例 #1
0
 @Override
 public void mousePressed(MouseEvent me) {
   x = me.getX();
   y = me.getY();
   altDown = me.isAltDown() || me.isAltGraphDown();
   undo = (me.getButton() == MouseEvent.BUTTON3) || altDown;
   ctrlDown = me.isControlDown() || me.isMetaDown();
   shiftDown = me.isShiftDown();
   first = true;
   if (!oneShot) {
     if (timer == null) {
       timer =
           new Timer(
               delay,
               e -> {
                 Point worldCoords = view.viewToWorld((int) x, (int) y);
                 tick(worldCoords.x, worldCoords.y, undo, first, 1.0f);
                 view.updateStatusBar(worldCoords.x, worldCoords.y);
                 first = false;
               });
       timer.setInitialDelay(0);
       timer.start();
       //                start = System.currentTimeMillis();
     }
   } else {
     Point worldCoords = view.viewToWorld((int) x, (int) y);
     tick(worldCoords.x, worldCoords.y, undo, true, 1.0f);
     view.updateStatusBar(worldCoords.x, worldCoords.y);
     Dimension dimension = getDimension();
     if (dimension != null) {
       dimension.armSavePoint();
     }
     logOperation(undo ? statisticsKeyUndo : statisticsKey);
   }
 }
コード例 #2
0
  /**
   * A chat room was selected. Opens the chat room in the chat window.
   *
   * @param e the <tt>MouseEvent</tt> instance containing details of the event that has just
   *     occurred.
   */
  public void mousePressed(MouseEvent e) {
    // Select the object under the right button click.
    if ((e.getModifiers() & InputEvent.BUTTON2_MASK) != 0
        || (e.getModifiers() & InputEvent.BUTTON3_MASK) != 0
        || (e.isControlDown() && !e.isMetaDown())) {
      int ix = this.chatRoomList.rowAtPoint(e.getPoint());

      if (ix != -1) {
        this.chatRoomList.setRowSelectionInterval(ix, ix);
      }
    }

    Object o = this.chatRoomsTableModel.getValueAt(this.chatRoomList.getSelectedRow());

    Point selectedCellPoint = e.getPoint();

    SwingUtilities.convertPointToScreen(selectedCellPoint, chatRoomList);

    if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) {
      JPopupMenu rightButtonMenu;

      if (o instanceof ChatRoomWrapper)
        rightButtonMenu = new ChatRoomRightButtonMenu((ChatRoomWrapper) o);
      else return;

      rightButtonMenu.setInvoker(this);
      rightButtonMenu.setLocation(selectedCellPoint);
      rightButtonMenu.setVisible(true);
    }
  }
コード例 #3
0
    public void mouseClicked(MouseEvent e) {
      details = String.format("You clicked %d", e.getClickCount());

      // isMetaDown() = what kind mouse is used now? one button or two
      // button or more?
      if (e.isMetaDown()) details += "with right mouse button";
      else if (e.isAltDown()) details += "with center mouse button";
      else details += "with left mouse";

      statusBar.setText(details);
    }
コード例 #4
0
ファイル: THA.java プロジェクト: tlulu/Tetris-Platformer
 /** Fires weapons when left mouse is pressed */
 public void mousePressed(MouseEvent evt) {
   int mx = evt.getX(); // x-coordinate where user clicked.
   int my = evt.getY(); // y-coordinate where user clicked.
   if (!pause) {
     if (!evt.isMetaDown()) {
       if (weapons[guntrack].equals("gun") && bshoot) {
         weaponList.add(
             new Bullet(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 7));
         bshoot = false;
         ammo.useBullet();
         bulletTime.restart();
       }
       if (weapons[guntrack].equals("grenade") && gshoot) {
         weaponList.add(
             new Grenade(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 12));
         gshoot = false;
         ammo.useGrenade();
         grenadeTime.restart();
       }
       if (weapons[guntrack].equals("laser") && lshoot) {
         weaponList.add(
             new Laser(
                 mx, my, character.getX(), character.getY(), 0, THA.WIDTH, 0, THA.HEIGHT, 20));
         lshoot = false;
         ammo.useLaser();
         laserTime.restart();
       }
       if (weapons[guntrack].equals("shotgun") && sgshoot) {
         weaponList.add(
             new ShotGun(
                 mx,
                 my,
                 character.getX(),
                 character.getY(),
                 0,
                 THA.WIDTH,
                 0,
                 THA.HEIGHT,
                 7,
                 character.getX(),
                 character.getY(),
                 25,
                 90,
                 weaponList));
         sgshoot = false;
         ammo.useShotgun();
         shotgunTime.restart();
       }
     }
   }
 }
コード例 #5
0
 @Override
 public void mouseMoved(MouseEvent me) {
   altDown = me.isAltDown() || me.isAltGraphDown();
   ctrlDown = me.isControlDown() || me.isMetaDown();
   shiftDown = me.isShiftDown();
 }