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

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

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

MouseEvent.getX介绍

[英]Returns the horizontal x position of the event relative to the source component.
[中]返回事件相对于源组件的水平x位置。

代码示例

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

public void mouseMoved (MouseEvent event) {
    int mouseX = event.getX();
    int mouseY = event.getY();
  }
});

代码示例来源:origin: stanfordnlp/CoreNLP

private void maybeShowPopup(MouseEvent e) {
 if (e.isPopupTrigger())
  treePopup.show(e.getComponent(), e.getX(), e.getY());
}

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

final JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(600, 400));
final JToolBar toolBar = new JToolBar();
button.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent e) {
    popup.show(e.getComponent(), e.getX(), e.getY());
toolBar.add(button);
frame.getContentPane().add(toolBar, BorderLayout.NORTH);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

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

public static void main ( String[] args )
{
  JFrame frame = new JFrame ();

  final JTree tree = new JTree ();
  tree.addMouseListener ( new MouseAdapter ()
  {
    public void mousePressed ( MouseEvent e )
    {
      if ( SwingUtilities.isRightMouseButton ( e ) )
      {
        TreePath path = tree.getPathForLocation ( e.getX (), e.getY () );
        Rectangle pathBounds = tree.getUI ().getPathBounds ( tree, path );
        if ( pathBounds != null && pathBounds.contains ( e.getX (), e.getY () ) )
        {
          JPopupMenu menu = new JPopupMenu ();
          menu.add ( new JMenuItem ( "Test" ) );
          menu.show ( tree, pathBounds.x, pathBounds.y + pathBounds.height );
        }
      }
    }
  } );
  frame.add ( tree );

  frame.pack ();
  frame.setLocationRelativeTo ( null );
  frame.setVisible ( true );
}

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

this.setLayout(new BorderLayout());
  checkBox = new JCheckBox();
  add(checkBox, BorderLayout.CENTER);
  setOpaque(false);
this.addMouseListener(new MouseListener() {
  public void mouseClicked(MouseEvent arg0) {
    TreePath tp = selfPointer.getPathForLocation(arg0.getX(), arg0.getY());
    if (tp == null) {
      return;

代码示例来源:origin: ron190/jsql-injection

@Override
  public void mouseReleased(MouseEvent evt) {
    if (evt.isPopupTrigger()) {
      // Fix #45348: IllegalComponentStateException on show()
      try {
        menu.show(evt.getComponent(), evt.getX(), evt.getY());
      } catch (IllegalComponentStateException e) {
        LOGGER.error(e, e);
      }
      
      menu.setLocation(
        ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
        ? evt.getXOnScreen() - menu.getWidth()
        : evt.getXOnScreen(),
        evt.getYOnScreen()
      );
    }
  }
});

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

TreePath path = m_tree.getPathForLocation(ev.getX(), 
        ev.getY());
    if (path != null)
s.getViewport().add(m_tree);
getContentPane().add(s, BorderLayout.CENTER);
setVisible(true);

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

c.addMouseListener(this);
c.addMouseMotionListener(this);
  dragView.removeMouseMotionListener(l);
dragView.setLocation(e.getX(), e.getY());
glassPane.add(dragView);

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

JFrame frame = new JFrame("Testing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(new TestPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
  if (e.getX() >= xOffset && e.getY() >= yOffset) {
    int column = (e.getX() - xOffset) / cellWidth;
    int row = (e.getY() - yOffset) / cellHeight;

代码示例来源:origin: org.codehaus.groovy/groovy

public void mouseReleased(MouseEvent e) {
    //if(e.isPopupTrigger())
    popup.show(scriptPane, e.getX(), e.getY());
  }
});

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

public void mousePressed(MouseEvent e) {
    point.x = e.getX();
    point.y = e.getY();
  }
});

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

add(checkBox, BorderLayout.WEST); 
  add(renderer, BorderLayout.CENTER);     
tree.addMouseListener(this); 
selectionModel.addTreeSelectionListener(this); 
TreePath path = tree.getPathForLocation(me.getX(), me.getY()); 
if(me.getX()/1.2>tree.getPathBounds(path).x+hotspot)

代码示例来源:origin: ron190/jsql-injection

@Override
public void mouseClicked(MouseEvent e) {
  if (SwingUtilities.isRightMouseButton(e)) {
    Component componentSource = (Component) e.getSource();
    JPopupMenu menu = new JPopupMenu();
    for (int position = 0 ; position < MediatorGui.menubar().getMenuView().getMenuComponentCount() ; position++) {
      // Fix #35348: SerializationException on clone()
      try {
        JMenuItem itemMenu = (JMenuItem) SerializationUtils.clone(MediatorGui.menubar().getMenuView().getMenuComponent(position));
        menu.add(itemMenu);
        
        final int positionFinal = position;
        itemMenu.addActionListener(actionEvent -> MediatorGui.tabManagers().setSelectedIndex(positionFinal));
      } catch (SerializationException ex) {
        LOGGER.error(ex, ex);
      }
    }
    menu.show(componentSource, e.getX(), e.getY());
    
    menu.setLocation(
      ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
      ? e.getXOnScreen() - menu.getWidth()
      : e.getXOnScreen(),
      e.getYOnScreen()
    );
  }
}

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

JFrame f = new JFrame("AnimationTest");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
timer.start();
this.setOpaque(false);
this.setPreferredSize(new Dimension(WIDE, HIGH));
this.addMouseListener(new MouseHandler());
this.addComponentListener(new ComponentHandler());
  JTextField field = new JTextField("test");
  Dimension d = field.getPreferredSize();
  field.setBounds(e.getX(), e.getY(), d.width, d.height);
  add(field);

代码示例来源:origin: igniterealtime/Smack

private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
      popup.show(e.getComponent(), e.getX(), e.getY());
    }
  }
}

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

public void mouseMoved (MouseEvent event) {
    int mouseX = event.getX();
    int mouseY = event.getY();
  }
});

代码示例来源:origin: ron190/jsql-injection

popupMenuList.show(
    list,
    ComponentOrientation.getOrientation(I18n.getLocaleDefault()) == ComponentOrientation.RIGHT_TO_LEFT
    ? mouseEvent.getX() - popupMenuList.getWidth()
    : mouseEvent.getX(),
    mouseEvent.getY()
  );
} catch (IllegalComponentStateException e) {

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

jPanel2.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent evt) {
    jPanel2MousePressed(evt);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
  currentX = evt.getX();
  currentY = evt.getY();
  oldX = currentX;
  oldY = currentY;
oldX = evt.getX();
oldY = evt.getY();
System.out.println(oldX + " " + oldY);
  currentX = evt.getX();
  currentY = evt.getY();
  System.out.println("line!!!! from" + oldX + "to" + currentX);
EventQueue.invokeLater(new Runnable() {
  public void run() {
    new JavaPaintUI().setVisible(true);

代码示例来源:origin: igniterealtime/Smack

private void maybeShowPopup(MouseEvent e) {
    if (e.isPopupTrigger()) {
      popup.show(e.getComponent(), e.getX(), e.getY());
    }
  }
}

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

public void mouseMoved (MouseEvent event) {
    int mouseX = event.getX();
    int mouseY = event.getY();
    int oldIndex = overIndex;
    overIndex = -1;
    int pointSize = isExpanded ? POINT_SIZE_EXPANDED : POINT_SIZE;
    int i = 0;
    for (Point point : points) {
      int x = chartX + (int)(chartWidth * (point.x / (float)maxX));
      int y = chartY + chartHeight - (int)(chartHeight * (point.y / (float)maxY));
      if (Math.abs(x - mouseX) <= pointSize && Math.abs(y - mouseY) <= pointSize) {
        overIndex = i;
        break;
      }
      i++;
    }
    if (overIndex != oldIndex) repaint();
  }
});

相关文章