java.awt.event.MouseListener类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(115)

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

MouseListener介绍

[英]The listener interface for receiving "interesting" mouse events (press, release, click, enter, and exit) on a component. (To track mouse moves and mouse drags, use the MouseMotionListener.)

The class that is interested in processing a mouse event either implements this interface (and all the methods it contains) or extends the abstract MouseAdapter class (overriding only the methods of interest).

The listener object created from that class is then registered with a component using the component's addMouseListener method. A mouse event is generated when the mouse is pressed, released clicked (pressed and released). A mouse event is also generated when the mouse cursor enters or leaves a component. When a mouse event occurs, the relevant method in the listener object is invoked, and the MouseEvent is passed to it.
[中]用于接收组件上“有趣”鼠标事件(按下、释放、单击、输入和退出)的侦听器界面。(要跟踪鼠标移动和鼠标拖动,请使用MouseMotionListener。)
对处理鼠标事件感兴趣的类要么实现此接口(及其包含的所有方法),要么扩展抽象MouseAdapter类(仅覆盖感兴趣的方法)。
然后使用组件的addMouseListener方法向组件注册从该类创建的侦听器对象。鼠标按下、释放或单击(按下并释放)时会生成鼠标事件。当鼠标光标进入或离开组件时,也会生成鼠标事件。当鼠标事件发生时,将调用侦听器对象中的相关方法,并将MouseEvent传递给它。

代码示例

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

MouseEvent me = new MouseEvent(tree, 0, 0, 0, 100, 100, 1, false);
for(MouseListener ml: tree.getMouseListeners()){
  ml.mousePressed(me);
}

代码示例来源:origin: org.cytoscape/plugin-impl

public void mouseClicked(final MouseEvent event) {
  if (event.getClickCount() > 1)
    m_listenerChain.mouseClicked(event);
}

代码示例来源:origin: com.jidesoft/jide-oss

public void mouseReleased(MouseEvent e) {
  if (_listener != null) {
    _listener.mouseReleased(e);
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

public void mousePressed(MouseEvent e) {
  if (panel.getMouseListeners() != null && panel.getMouseListeners().length != 0) {
    MouseEvent e2 = new MouseEvent(panel, e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(),
        e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
    for (MouseListener m : panel.getMouseListeners()) {
      m.mousePressed(e2);
    }
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-mobility-svgcore

public void mousePressed (MouseEvent e) {
  if ( ( (TapPanel) e.getSource () ).isArmPoint ( e.getPoint () ) ) {
    ( (TapPanel) e.getSource () ).setExpanded ( !( (TapPanel) e.getSource () ).isExpanded () );
    e.consume ();
  } else if ( other != null ) {
    other.mousePressed ( e );
  }
}

代码示例来源:origin: com.eas.platypus/platypus-js-forms

@Override
public void mousePressed(MouseEvent e) {
  MouseListener[] mls = getMouseListeners();
  if (mls != null && e.getSource() instanceof Component) {
    e = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, ModelComponentDecorator.this);
    for (MouseListener ml : mls) {
      ml.mousePressed(e);
    }
  }
}

代码示例来源:origin: com.eas.platypus/platypus-js-forms

@Override
public void mouseReleased(MouseEvent e) {
  if (e.getSource() instanceof Component) {
    e = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, ModelGrid.this);
    for (MouseListener l : ModelGrid.this.getMouseListeners()) {
      l.mouseReleased(e);
    }
  }
}

代码示例来源:origin: gurkenlabs/litiengine

@Override
public void mouseEntered(final MouseEvent e) {
 if (!this.grabMouse) {
  this.lastLocation = e.getPoint();
  this.location = e.getPoint();
 } else {
  this.setLocation(e);
 }
 final MouseEvent wrappedEvent = this.createEvent(e);
 this.mouseListeners.forEach(listener -> listener.mouseEntered(wrappedEvent));
}

代码示例来源:origin: com.eas.platypus/platypus-js-forms

@Override
  public void mouseExited(MouseEvent e) {
    MouseListener[] mls = getMouseListeners();
    if (mls != null && e.getSource() instanceof Component) {
      e = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, ModelComponentDecorator.this);
      for (MouseListener ml : mls) {
        ml.mouseExited(e);
      }
    }
  }
});

代码示例来源:origin: com.eas.platypus/platypus-js-forms

@Override
public void mouseClicked(MouseEvent e) {
  if (e.getSource() instanceof Component) {
    e = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, ModelGrid.this);
    for (MouseListener l : ModelGrid.this.getMouseListeners()) {
      l.mouseClicked(e);
    }
  }
}

代码示例来源:origin: com.eas.platypus/platypus-js-forms

@Override
public void mouseEntered(MouseEvent e) {
  if (e.getSource() instanceof Component) {
    e = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, ModelGrid.this);
    for (MouseListener l : ModelGrid.this.getMouseListeners()) {
      l.mouseEntered(e);
    }
  }
}

代码示例来源:origin: net.sf.jung/jung-visualization

public void mousePressed(MouseEvent e) {
  checkMouseListeners();
  for(int i=0; i<mouseListeners.length; i++) {
    mouseListeners[i].mousePressed(e);
    if(e.isConsumed()) break;
  }
}

代码示例来源:origin: net.sf.jung/jung-visualization

public void mouseClicked(MouseEvent e) {
  checkMouseListeners();
  for(int i=0; i<mouseListeners.length; i++) {
    mouseListeners[i].mouseClicked(e);
    if(e.isConsumed()) break;
  }
}

代码示例来源:origin: net.sf.jung/jung-visualization

public void mouseReleased(MouseEvent e) {
  checkMouseListeners();
  for(int i=0; i<mouseListeners.length; i++) {
    mouseListeners[i].mouseReleased(e);
    if(e.isConsumed()) break;
  }
}

代码示例来源:origin: jrtom/jung

public void mouseEntered(MouseEvent e) {
 checkMouseListeners();
 for (int i = 0; i < mouseListeners.length; i++) {
  mouseListeners[i].mouseEntered(e);
  if (e.isConsumed()) {
   break;
  }
 }
}

代码示例来源:origin: jrtom/jung

public void mouseExited(MouseEvent e) {
 checkMouseListeners();
 for (int i = 0; i < mouseListeners.length; i++) {
  mouseListeners[i].mouseExited(e);
  if (e.isConsumed()) {
   break;
  }
 }
}

代码示例来源:origin: khuxtable/seaglass

/**
 * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
 */
public void mouseClicked(MouseEvent e) {
  delegate.mouseClicked(e);
}

代码示例来源:origin: com.jidesoft/jide-oss

public void mouseEntered(MouseEvent e) {
  if (_listener != null) {
    _listener.mouseEntered(e);
  }
}

代码示例来源:origin: org.japura/japura-gui

@Override
public void mouseExited(MouseEvent e) {
 mouseIn = false;
 originalMouseListener.mouseExited(e);
}

代码示例来源:origin: org.activecomponents.jadex/jadex-kernel-extension-envsupport

public void mousePressed(MouseEvent e)
{
  e.setSource(AbstractInteractionPlugin.this);
  if (listeners != null)
    for (Iterator it = listeners.iterator(); it.hasNext(); )
      ((MouseListener) it.next()).mousePressed(e);
}

相关文章