我想在java小程序中使用Robot类来让网络浏览器移动和单击鼠标

发布于 2024-08-03 04:45:27 字数 717 浏览 4 评论 0原文

我创建了这个小程序,它将鼠标移动到屏幕上的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橘虞初梦 2024-08-10 04:45:27

单独签名不会授予您的 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.

皇甫轩 2024-08-10 04:45:27

我检查了 Robot 的源代码。我认为你必须在构造函数中添加 ScreenDevice。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文