java.awt.event.MouseEvent.getButton()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(281)

本文整理了Java中java.awt.event.MouseEvent.getButton()方法的一些代码示例,展示了MouseEvent.getButton()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MouseEvent.getButton()方法的具体详情如下:
包路径:java.awt.event.MouseEvent
类名称:MouseEvent
方法名:getButton

MouseEvent.getButton介绍

[英]Returns which, if any, of the mouse buttons has changed state.
[中]返回哪一个鼠标按钮(如果有)已更改状态。

代码示例

代码示例来源:origin: stackoverflow.com

myNode.setOnMouseClicked(new EventHandler<MouseEvent>() {
  @Override
  public void handle(MouseEvent mouseEvent) {
    if(mouseEvent.getButton().equals(MouseButton.PRIMARY)){
      if(mouseEvent.getClickCount() == 2){
        System.out.println("Double clicked");
      }
    }
  }
});

代码示例来源:origin: stackoverflow.com

public void mouseClicked(MouseEvent e) {
 if ((e.getButton() == 1) && oval.contains(e.getX(), e.getY()) ) {
  repaint();
 // JOptionPane.showMessageDialog(null,e.getX()+ "\n" + e.getY());
 }
}

代码示例来源:origin: runelite/runelite

private MouseEvent translateEvent(MouseEvent e)
  {
    Dimension stretchedDimensions = client.getStretchedDimensions();
    Dimension realDimensions = client.getRealDimensions();

    int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
    int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

    return new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(),
        newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getButton());
  }
}

代码示例来源:origin: xyz.cofe/gui.swing

public TableCellMouseEvent( MouseEvent sample ){
  super(sample.getComponent(), 
    sample.getID(), 
    sample.getWhen(), 
    sample.getModifiers(), 
    sample.getX(), sample.getY(), 
    sample.getXOnScreen(), sample.getYOnScreen(), 
    sample.getClickCount(), 
    sample.isPopupTrigger(), 
    sample.getButton()
  );
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

public void mouseClicked(MouseEvent e) {
  TableColumnModel columnModel = getColumnModel();
  int viewColumn = columnModel.getColumnIndexAtX(e.getX());
  int column = convertColumnIndexToModel(viewColumn);
  if (    (e.getButton() == MouseEvent.BUTTON1)
     && (e.getClickCount() == 2)
     && (column != -1) )
   JTableHelper.setOptimalColumnWidth(table, column);
 }
});

代码示例来源:origin: bobbylight/RSyntaxTextArea

@Override
public void mousePressed(MouseEvent e) {
  if (textArea==null) {
    return;
  }
  if (e.getButton()==MouseEvent.BUTTON1) {
    int pos = textArea.viewToModel(new Point(0, e.getY()));
    if (pos>=0) { // Not -1
      textArea.setCaretPosition(pos);
    }
    mouseDragStartOffset = pos;
  }
  else {
    mouseDragStartOffset = -1;
  }
}

代码示例来源:origin: nodebox/nodebox

public void mousePressed(MouseEvent e) {
  if (!isEnabled()) return;
  if (!inDraggableArea(e.getPoint())) return;
  if (e.getButton() == MouseEvent.BUTTON1) {
    isDragging = true;
    oldValue = getValue();
    previousX = e.getX();
    SwingUtilities.getRootPane(this).setCursor(dragCursor);
  }
}

代码示例来源:origin: geotools/geotools

/**
 * Creates a new event instance.
 *
 * @param pane the source map pane
 * @param event the source mouse event
 */
public MapMouseEvent(MapPane pane, MouseEvent event) {
  super(
      (Component) pane,
      event.getID(),
      event.getWhen(),
      event.getModifiers(),
      event.getX(),
      event.getY(),
      event.getClickCount(),
      event.isPopupTrigger(),
      event.getButton());
  worldCoords = calculateWorldPos(pane, event);
  isWheelEvent = false;
  wheelAmount = 0;
}

代码示例来源:origin: libgdx/libgdx

@Override
public void mousePressed (MouseEvent e) {
  synchronized (this) {
    TouchEvent event = usedTouchEvents.obtain();
    event.pointer = 0;
    event.x = e.getX();
    event.y = e.getY();
    event.type = TouchEvent.TOUCH_DOWN;
    event.button = toGdxButton(e.getButton());
    event.timeStamp = System.nanoTime();
    touchEvents.add(event);
    deltaX = event.x - touchX;
    deltaY = event.y - touchY;
    touchX = event.x;
    touchY = event.y;
    touchDown = true;
    pressedButtons.add(event.button);
    lwjglAwtCanvas.graphics.requestRendering();
  }
}

代码示例来源:origin: de.sciss/jtreetable

public TreeTableMouseEvent(TreeTable source, MouseEvent e) {
  super(source, e.getID(), e.getWhen(), e.getModifiers(),
      e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(),
      e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

代码示例来源:origin: nodebox/nodebox

public void mouseDragged(MouseEvent e) {
  isDragging = true;
  JComponent c = ColorWell.this;
  Point pt = e.getPoint();
  JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
  pt = SwingUtilities.convertPoint(c, pt, frame.getContentPane());
  MouseEvent newEvent = new MouseEvent(colorPicker, e.getID(), e.getWhen(), e.getModifiers(), (int) pt.getX(), (int) pt.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
  colorPicker.dispatchEvent(newEvent);
}

代码示例来源:origin: RaiMan/SikuliX2

private void myMouseClicked(MouseEvent e) {
 String doubleClick = e.getClickCount() > 1 ? "Double" : "";
 String rightClick = e.getButton() != MouseEvent.BUTTON1 ? "Right" : "";
 log.trace("mouse%s%sClicked: %d,%d", rightClick, doubleClick, e.getX(), e.getY());
 if (SX.isSet(doubleClick)) {
  if (SX.isNotSet(rightClick)) {
   eventState(CLICKDOUBLE, e.getX(), e.getY());
  }
 } else if (SX.isSet(rightClick)) {
  eventState(CLICKRIGHT, e.getX(), e.getY());
 } else {
  eventState(CLICKLEFT, e.getX(), e.getY());
 }
}

代码示例来源:origin: libgdx/libgdx

@Override
public void mouseReleased (MouseEvent e) {
  synchronized (this) {
    TouchEvent event = usedTouchEvents.obtain();
    event.pointer = 0;
    event.x = e.getX();
    event.y = e.getY();
    event.button = toGdxButton(e.getButton());
    event.type = TouchEvent.TOUCH_UP;
    event.timeStamp = System.nanoTime();
    touchEvents.add(event);
    deltaX = event.x - touchX;
    deltaY = event.y - touchY;
    touchX = event.x;
    touchY = event.y;
    pressedButtons.remove(event.button);
    if (pressedButtons.size == 0) touchDown = false;
    lwjglAwtCanvas.graphics.requestRendering();
  }
}

代码示例来源:origin: nroduit/Weasis

public MouseEventDouble(MouseEvent e) {
  this((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(), e.getXOnScreen(),
    e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

代码示例来源:origin: nodebox/nodebox

public void mouseDragged(MouseEvent e) {
  isDragging = true;
  JComponent c = ColorWell.this;
  Point pt = e.getPoint();
  JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(c);
  pt = SwingUtilities.convertPoint(c, pt, frame.getContentPane());
  MouseEvent newEvent = new MouseEvent(colorPicker, e.getID(), e.getWhen(), e.getModifiers(), (int) pt.getX(), (int) pt.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
  colorPicker.dispatchEvent(newEvent);
}

代码示例来源:origin: net.sf.ingenias/editor

void moduleOutput_mouseClicked(MouseEvent e) {
  if (e.getClickCount() == 2 || e.getButton() == e.BUTTON3) {
    this.messagesMenu.show(this.moduleOutput, e.getX(), e.getY());
  }
}

代码示例来源:origin: libgdx/libgdx

@Override
public void mousePressed (MouseEvent e) {
  synchronized (this) {
    TouchEvent event = usedTouchEvents.obtain();
    event.pointer = 0;
    event.x = e.getX();
    event.y = e.getY();
    event.type = TouchEvent.TOUCH_DOWN;
    event.button = toGdxButton(e.getButton());
    event.timeStamp = System.nanoTime();
    touchEvents.add(event);
    deltaX = event.x - touchX;
    deltaY = event.y - touchY;
    touchX = event.x;
    touchY = event.y;
    touchDown = true;
    pressedButtons.add(event.button);
    lwjglAwtCanvas.graphics.requestRendering();
  }
}

代码示例来源:origin: net.java.openjdk.cacio/cacio-shared

void handleMouseMotionEvent(MouseEvent e) {
  MouseEvent me = new MouseEvent(this, e.getID(), e.getWhen(),
                  e.getModifiers(), e.getX(), e.getY(),
                  e.getXOnScreen(), e.getYOnScreen(),
                  e.getClickCount(), e.isPopupTrigger(),
                  e.getButton());
  // IMPORTANT: See comment on the helper method!
  doLightweightDispatching(e);
}

代码示例来源:origin: magefree/mage

@Override
public void mouseClicked(MouseEvent e) {
  if ((e.getClickCount() & 1) == 0 && (e.getClickCount() > 0)) { // double clicks and repeated double clicks
    if (e.getButton() == MouseEvent.BUTTON1) {
      Object obj = e.getSource();
      if (obj instanceof MageCard) {
        this.cardEventSource.fireEvent(((MageCard)obj).getOriginal(), ClientEventType.PICK_A_CARD);
        this.hidePopup();
        AudioManager.playOnDraftSelect();
      }
    }
  }
}

代码示例来源:origin: net.sf.ingenias/editor

void logs_mouseClicked(MouseEvent e) {
  if (e.getClickCount() == 2 || e.getButton() == e.BUTTON3) {
    this.messagesMenu.show(this.logs, e.getX(), e.getY());
  }
}

相关文章