本文整理汇总了Java中java.awt.event.MouseMotionListener类的典型用法代码示例。如果您正苦于以下问题:Java MouseMotionListener类的具体用法?Java MouseMotionListener怎么用?Java MouseMotionListener使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MouseMotionListener类属于java.awt.event包,在下文中一共展示了MouseMotionListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
public void init() {
if (script == null) {
throw new RuntimeException("Script is null");
}
if (script instanceof MouseListener) {
addMouseListener((MouseListener) script);
}
if (script instanceof MouseMotionListener) {
addMouseMotionListener((MouseMotionListener) script);
}
if (script instanceof MessageListener) {
addMessageListener((MessageListener) script);
}
if (script instanceof Paintable) {
Context.getInstance().addPaintable((Paintable) script);
}
if (script instanceof GameActionListener) {
addActionListener((GameActionListener) script);
}
}
示例2: addCurrentLineHighlightListeners
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Adds listeners that listen for changes to the current line, so we can
* update our "current line highlight." This is needed only because of an
* apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2,
* not needed on 1.5.0).
*/
private void addCurrentLineHighlightListeners() {
boolean add = true;
MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
for (int i=0; i<mouseMotionListeners.length; i++) {
if (mouseMotionListeners[i]==mouseListener) {
add = false;
break;
}
}
if (add) {
//System.err.println("Adding mouse motion listener!");
addMouseMotionListener(mouseListener);
}
MouseListener[] mouseListeners = getMouseListeners();
for (int i=0; i<mouseListeners.length; i++) {
if (mouseListeners[i]==mouseListener) {
add = false;
break;
}
}
if (add) {
//System.err.println("Adding mouse listener!");
addMouseListener(mouseListener);
}
}
示例3: containsInGameComponents
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Checks if this {@code Canvas} contains any in game components.
*
* @return {@code true} if there is any in game components.
*/
public boolean containsInGameComponents() {
KeyListener[] keyListeners = getKeyListeners();
if (keyListeners.length > 0) {
return true;
}
MouseListener[] mouseListeners = getMouseListeners();
if (mouseListeners.length > 0) {
return true;
}
MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
if (mouseMotionListeners.length > 0) {
return true;
}
return false;
}
示例4: removeInGameComponents
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Removes components that is only used when in game.
*/
public void removeInGameComponents() {
// remove listeners, they will be added when launching the new game...
KeyListener[] keyListeners = getKeyListeners();
for (KeyListener keyListener : keyListeners) {
removeKeyListener(keyListener);
}
MouseListener[] mouseListeners = getMouseListeners();
for (MouseListener mouseListener : mouseListeners) {
removeMouseListener(mouseListener);
}
MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
for (MouseMotionListener mouseMotionListener : mouseMotionListeners) {
removeMouseMotionListener(mouseMotionListener);
}
for (Component c : getComponents()) {
removeFromCanvas(c);
}
}
示例5: InGameMenuBar
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Creates a new {@code FreeColMenuBar}. This menu bar will include
* all of the submenus and items.
*
* @param freeColClient The main controller.
* @param listener An optional mouse motion listener.
*/
public InGameMenuBar(FreeColClient freeColClient, MouseMotionListener listener) {
// FIXME: FreeColClient should not have to be passed in to
// this class. This is only a menu bar, it doesn't need a
// reference to the main controller. The only reason it has
// one now is because DebugMenu needs it. And DebugMenu needs
// it because it is using inner classes for ActionListeners
// and those inner classes use the reference. If those inner
// classes were in seperate classes, when they were created,
// they could use the FreeColClient reference of the
// ActionManger. So DebugMenu needs to be refactored to remove
// inner classes so that this MenuBar can lose its unnecessary
// reference to the main controller. See FreeColMenuTest.
//
// Okay, I lied.. the update() and paintComponent() methods in
// this MenuBar use freeColClient, too. But so what. Move
// those to another class too. :)
super(freeColClient);
// Add a mouse listener so that autoscrolling can happen in
// this menubar
this.addMouseMotionListener(listener);
reset();
}
示例6: addListener
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Adds an event listener to the Panel.
*
* @param eventListener
* The event listener.
*
* @throws IllegalArgumentException
* If the event listener isn't supported by this function.
*/
public void addListener(final EventListener eventListener) {
if (eventListener instanceof KeyListener) {
this.addKeyListener((KeyListener) eventListener);
return;
}
if (eventListener instanceof MouseListener) {
this.addMouseListener((MouseListener) eventListener);
return;
}
if (eventListener instanceof MouseMotionListener) {
this.addMouseMotionListener((MouseMotionListener) eventListener);
return;
}
throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported.");
}
示例7: removeListener
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Removes an event listener from the Panel.
*
* @param eventListener
* The event listener.
*
* @throws IllegalArgumentException
* If the event listener isn't supported by this function.
*/
public void removeListener(final EventListener eventListener) {
if (eventListener instanceof KeyListener) {
this.removeKeyListener((KeyListener) eventListener);
return;
}
if (eventListener instanceof MouseListener) {
this.removeMouseListener((MouseListener) eventListener);
return;
}
if (eventListener instanceof MouseMotionListener) {
this.removeMouseMotionListener((MouseMotionListener) eventListener);
return;
}
throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported.");
}
示例8: init
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
public void init() {
if (script == null) {
throw new RuntimeException("Script is null");
}
if (script instanceof MouseListener) {
addMouseListener((MouseListener) script);
}
if (script instanceof MouseMotionListener) {
addMouseMotionListener((MouseMotionListener) script);
}
// if (script instanceof MessageListener) {
// addMessageListener((MessageListener) script);
// }
if (script instanceof Paintable) {
Context.getInstance().addPaintable((Paintable) script);
}
// if (script instanceof GameActionListener) {
// addActionListener((GameActionListener) script);
// }
}
示例9: removeListener
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
public void removeListener() {
for (MouseListener ml : com.getMouseListeners()) {
com.removeMouseListener(ml);
}
for (MouseMotionListener mml : com.getMouseMotionListeners()) {
com.removeMouseMotionListener(mml);
}
for (KeyListener kl : com.getKeyListeners()) {
com.removeKeyListener(kl);
}
reset();
com.repaint();
}
示例10: setMouseAndKeyListeners
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Sets up mouse and key listeners
*/
protected void setMouseAndKeyListeners( MouseInputListener mouseHandler, KeyListener keyAdapter ) {
// Clear the old handlers
MouseListener[] mouseListeners = this.getMouseListeners();
for ( int i = 0; i < mouseListeners.length; i++ ) {
MouseListener mouseListener = mouseListeners[i];
this.removeMouseListener( mouseListener );
}
MouseMotionListener[] mouseMostionListeners = this.getMouseMotionListeners();
for ( int i = 0; i < mouseMostionListeners.length; i++ ) {
MouseMotionListener mouseMostionListener = mouseMostionListeners[i];
this.removeMouseMotionListener( mouseMostionListener );
}
KeyListener[] keyListeners = this.getKeyListeners();
for ( int i = 0; i < keyListeners.length; i++ ) {
KeyListener keyListener = keyListeners[i];
this.removeKeyListener( keyListener );
}
// Add the new handlers
this.addMouseListener( mouseHandler );
this.addMouseMotionListener( getGraphic().getMouseHandler() );
this.addKeyListener( keyAdapter );
}
示例11: setMovable
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Set whether the coordinate system is movable with the mouse, i.e.
* the scope of the system changes as the the mouse is clicked, held
* and dragged over the system.
*
* @param movable
* If true, move is possible.
*/
public void setMovable(boolean movable) {
if (this.movable && movable) return;
if (!this.movable && !movable) return;
if (movable) {
addMouseListener(mouseListener);
addMouseMotionListener((MouseMotionListener) mouseListener);
}
else {
removeMouseListener(mouseListener);
removeMouseMotionListener((MouseMotionListener) mouseListener);
}
movable = !movable;
}
示例12: addCurrentLineHighlightListeners
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Adds listeners that listen for changes to the current line, so we can
* update our "current line highlight." This is needed only because of an
* apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2,
* not needed on 1.5.0).
*/
private void addCurrentLineHighlightListeners() {
boolean add = true;
MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
for (int i=0; i<mouseMotionListeners.length; i++) {
if (mouseMotionListeners[i]==mouseListener) {
add = false;
break;
}
}
if (add==true) {
//System.err.println("Adding mouse motion listener!");
addMouseMotionListener(mouseListener);
}
MouseListener[] mouseListeners = getMouseListeners();
for (int i=0; i<mouseListeners.length; i++) {
if (mouseListeners[i]==mouseListener) {
add = false;
break;
}
}
if (add==true) {
//System.err.println("Adding mouse listener!");
addMouseListener(mouseListener);
}
}
示例13: addCurrentLineHighlightListeners
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
/**
* Adds listeners that listen for changes to the current line, so we can update our "current line highlight." This
* is needed only because of an apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2, not needed on
* 1.5.0).
*/
protected void addCurrentLineHighlightListeners() {
boolean add = true;
MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners();
for (int i = 0; i < mouseMotionListeners.length; i++) {
if (mouseMotionListeners[i] == mouseListener) {
add = false;
break;
}
}
if (add == true) {
// System.err.println("Adding mouse motion listener!");
addMouseMotionListener(mouseListener);
}
MouseListener[] mouseListeners = getMouseListeners();
for (int i = 0; i < mouseListeners.length; i++) {
if (mouseListeners[i] == mouseListener) {
add = false;
break;
}
}
if (add == true) {
// System.err.println("Adding mouse listener!");
addMouseListener(mouseListener);
}
}
示例14: notifyMouseMotionListeners
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
public void notifyMouseMotionListeners(final MouseEvent e) {
SwingWorker worker = new SwingWorker<String, Object>() {
@Override
public String doInBackground() {
if (mouseMotionListeners != null) {
e.setSource(this);
ListIterator<MouseMotionListener> iter = mouseMotionListeners.listIterator();
while (iter.hasNext()) {
MouseMotionListener listener = iter.next();
switch (e.getID()) {
case MouseEvent.MOUSE_MOVED:
listener.mouseMoved(e);
break;
case MouseEvent.MOUSE_DRAGGED:
listener.mouseDragged(e);
break;
default:
break;
}
}
iter = null;
}
return null;
}
};
worker.execute();
try {
worker.get();
} catch (Exception ie) {
}
}
示例15: notifyMouseMotionListeners
import java.awt.event.MouseMotionListener; //导入依赖的package包/类
public void notifyMouseMotionListeners(MouseEvent e) {
if (mouseMotionListeners != null) {
e.setSource(this);
ListIterator<MouseMotionListener> iter = mouseMotionListeners.listIterator();
while (iter.hasNext()) {
MouseMotionListener listener = iter.next();
switch (e.getID()) {
case MouseEvent.MOUSE_MOVED:
listener.mouseMoved(e);
break;
case MouseEvent.MOUSE_DRAGGED:
listener.mouseDragged(e);
break;
default:
break;
}
}
iter = null;
}
}