我想在java小程序中使用Robot类来让网络浏览器移动和单击鼠标
我创建了这个小程序,它将鼠标移动到屏幕上的 1000 个位置。它可以作为应用程序运行,但不能在小程序中运行。我已经创建了签名小程序,但它仍然不会移动鼠标。我应该怎么做才能让我的机器人类在浏览器中工作?我的代码如下:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Robot;
import java.awt.AWTException;
public class s extends Applet {
public void paint(Graphics g) {
g.drawString("Test1", 10, 10);
}
public void init() {
try {
Robot robot = new Robot();
robot.mouseMove(1000,50);
System.out.println("code executes");
} catch (Exception ex) {
System.out.println("code failed");
};
}
}
I have created this applet, It moves mouse to 1000 pos on screen. It works as application but it does not work in applet. I have created signed applet but still it wont move mouse. What should I do to make my Robot class work from browser? My code is as below:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Robot;
import java.awt.AWTException;
public class s extends Applet {
public void paint(Graphics g) {
g.drawString("Test1", 10, 10);
}
public void init() {
try {
Robot robot = new Robot();
robot.mouseMove(1000,50);
System.out.println("code executes");
} catch (Exception ex) {
System.out.println("code failed");
};
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
单独签名不会授予您的 Applet 任何权限。您需要向您的 Applet 授予
createRobot
权限。有关更多详细信息,请查看安全教程。
Signing alone won't give your Applet any permissions. You need to grant the
createRobot
permission to your Applet.Check the security tutorials for more details.
我检查了 Robot 的源代码。我认为你必须在构造函数中添加 ScreenDevice。
I've checked the source-code from Robot. And I think you have to add in the constructor a ScreenDevice.