我想在Java小程序中使用Robot类来使Web浏览器移动并单击鼠标 [英] I want to use Robot class in java applet for web browser to move and click mouse
本文介绍了我想在Java小程序中使用Robot类来使Web浏览器移动并单击鼠标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了这个applet,它将鼠标移至屏幕上的1000 pos.它可以作为应用程序使用,但不能在applet中使用.我已经创建了签名小程序,但仍然不会移动鼠标.我该怎么做才能使我的Robot类在浏览器中正常工作?我的代码如下:
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");
};
}
}
推荐答案
单独签名不会给您的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.
这篇关于我想在Java小程序中使用Robot类来使Web浏览器移动并单击鼠标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文