【发布时间】:2014-07-29 23:51:47
【问题描述】:
问题在于鼠标的移动
Integer yCoords = evt.getY();
将鼠标视为 y 轴上的一个钟摆,它上下移动。
我需要将 yAxis 的值从鼠标的停止点自动增加到 100,
但是当鼠标移回 50 时,最终结果应该增加到 150,当它回到 100 时应该是 200(再次自动增加 50)
yCoords += yCoords;
不会这样做
【问题讨论】:
问题在于鼠标的移动
Integer yCoords = evt.getY();
将鼠标视为 y 轴上的一个钟摆,它上下移动。
我需要将 yAxis 的值从鼠标的停止点自动增加到 100,
但是当鼠标移回 50 时,最终结果应该增加到 150,当它回到 100 时应该是 200(再次自动增加 50)
yCoords += yCoords;
不会这样做
【问题讨论】:
公共静态整数结果;
int y = evt.getY();
int i = 0;
while (i < 1) {
result += y;
try {
Thread.sleep(1000);
i++;
} catch (InterruptedException e) {
e.printStackTrace();
}
for (int x = -result; x <= result; x++) {
p.addPoint(-x , 100- (int) (50 * fSin((x / 100.0) * 2
* Math.PI)));
}
System.out.println(result);
}
我的代码中基本上缺少的是一个全局变量!这将在一段时间内存储 Y 的最后一个位置,这对于我的需要是 1 秒。 y 的最后一个位置的 var 将是新 Y 位置的计数的引用。
就这么简单!
【讨论】:
我认为您正在寻找的是“机器人”。
看看这个方法:http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html#mouseMove%28int,%20int%29
您应该能够将所需的坐标传递给它!
示例来自:Moving the cursor in Java
try {
// These coordinates are screen coordinates
int xCoord = 500;
int yCoord = 500;
// Move the cursor
Robot robot = new Robot();
robot.mouseMove(xCoord, yCoord);
} catch (AWTException e) {
}
【讨论】: