1个回答
展开全部
你可以调用Container的getMousePosition(boolean allowChildren)方法,或者Component的getMousePosition(),以后你碰到问题可以多查API。
控制台程序是吧,给你个示例程序:
import java.awt.MouseInfo;
import java.awt.Point;
import java.util.Timer;
import java.util.TimerTask;
public final class MouseEventTest {
public static void main(String[] args) {
System.out.println("This is a mouse location test project.");
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Point point = MouseInfo.getPointerInfo().getLocation();
System.out.println("Location:x=" + point.x + ", y=" + point.y);
}
}, 100, 100);
}
}
控制台程序是吧,给你个示例程序:
import java.awt.MouseInfo;
import java.awt.Point;
import java.util.Timer;
import java.util.TimerTask;
public final class MouseEventTest {
public static void main(String[] args) {
System.out.println("This is a mouse location test project.");
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Point point = MouseInfo.getPointerInfo().getLocation();
System.out.println("Location:x=" + point.x + ", y=" + point.y);
}
}, 100, 100);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询