I want to use Robot class in java applet for web browser to move and click mouse

被刻印的时光 ゝ 提交于 2019-12-01 05:30:54

问题


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");
                };
        }
}

回答1:


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.




回答2:


I've checked the source-code from Robot. And I think you have to add in the constructor a ScreenDevice.



来源:https://stackoverflow.com/questions/1321999/i-want-to-use-robot-class-in-java-applet-for-web-browser-to-move-and-click-mouse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!