繁体   English   中英

机器人类在小程序范围内的点击

[英]Robot class clicks within confines of applet

对我而言,robot类有效,但使用robot.mouseMouse(x, y); 将是屏幕的x和y。 我如何使它仅在applet本身的范围之内? 因此,换句话说,坐标1,1通常将位于屏幕的左上方,但我希望它位于小程序的左上方。

这是如何实现的?

您可以计算位置。 您可以要求它的Location

myApplet.getLocation();

并为其大小

myApplet.getSize();

这样您就可以创建一个方法

public void mouseToPosition(int x, int y){
    int zeroPosX = myApplet.getLocation().getX();
    int zeroPosY = myApplet.getLocation().getY();

    int newPosX = zeroPosX + x;
    int newPosY = zeroPosY + y;

    ...
    //now you have to check if it's in the bounds of the Applet, maybe throw an error
    //and you can add your click/move/whatever robot logic
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM