如何注册 MousemotionListener
How to register MousemotionListener
如何在不使用 Applet、JFrame、JPanel 或 anything.Because 的情况下注册 MouseMotionListener anything.Because 我想在鼠标刚刚在系统中移动时捕获鼠标位置?
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.*;
import java.awt.*;
class Mouseposition extends MouseAdapter
{
public void mouseMoved(MouseEvent e)
{
System.out.println("MOuse x : "+MouseInfo.getPointerInfo().getLocation().x+ "Mouse Y : "+MouseInfo.getPointerInfo().getLocation().y);
}
public static void main(String args[])
{
//--- register for Mouse events
----
while(true);
}
}
你不能,Java 不会以这种方式监听全局 OS 事件。
对于 example or example or use a Thread
to constantly poll the MouseInfo
class, for example and example,您可以使用 JNI/JNA 挂钩到 OS,这可能不是很有效...
如何在不使用 Applet、JFrame、JPanel 或 anything.Because 的情况下注册 MouseMotionListener anything.Because 我想在鼠标刚刚在系统中移动时捕获鼠标位置?
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.*;
import java.awt.*;
class Mouseposition extends MouseAdapter
{
public void mouseMoved(MouseEvent e)
{
System.out.println("MOuse x : "+MouseInfo.getPointerInfo().getLocation().x+ "Mouse Y : "+MouseInfo.getPointerInfo().getLocation().y);
}
public static void main(String args[])
{
//--- register for Mouse events
----
while(true);
}
}
你不能,Java 不会以这种方式监听全局 OS 事件。
对于 example or example or use a Thread
to constantly poll the MouseInfo
class, for example and example,您可以使用 JNI/JNA 挂钩到 OS,这可能不是很有效...