编译像素识别脚本时出现Javac错误

发布于 2025-01-01 08:02:41 字数 1065 浏览 1 评论 0原文

好吧,J Barclay 解决了我的所有问题,除了一个问题!耶!!

无法从静态上下文引用非静态方法 getRGB()。

第 28 行-

新代码-

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Robot;
    import java.awt.AWTException;
    import java.awt.Rectangle;
    import java.awt.Color;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;

    public class GunningBot{
    public static void main(String[] args) throws Exception{

    Robot robot = new Robot();
Color color = new Color(195, 174, 196);

{
Rectangle rectangle = new Rectangle(0, 0, 1075, 700);

    {
    BufferedImage image = robot.createScreenCapture(rectangle);
    search: for(int x = 0; x < rectangle.getWidth(); x++)
    {
        for(int y = 0; y < rectangle.getHeight(); y++)
        {
            if(image.getRGB(x, y) == Color.getRGB())
            {
                robot.mouseMove(x, y);
                break search;
            }
        }
    }
    }
    }

Well J Barclay cleared up all but one of my problems!! yay!!

non-static method getRGB() cannot be referenced from a static context.

line 28-

new code-

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.Robot;
    import java.awt.AWTException;
    import java.awt.Rectangle;
    import java.awt.Color;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.imageio.ImageIO;

    public class GunningBot{
    public static void main(String[] args) throws Exception{

    Robot robot = new Robot();
Color color = new Color(195, 174, 196);

{
Rectangle rectangle = new Rectangle(0, 0, 1075, 700);

    {
    BufferedImage image = robot.createScreenCapture(rectangle);
    search: for(int x = 0; x < rectangle.getWidth(); x++)
    {
        for(int y = 0; y < rectangle.getHeight(); y++)
        {
            if(image.getRGB(x, y) == Color.getRGB())
            {
                robot.mouseMove(x, y);
                break search;
            }
        }
    }
    }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

妳是的陽光 2025-01-08 08:02:41

第一个问题是您正在访问 Robot 类的实例方法而不是 robots 的实例。

只需更改大小写即可修复:

BufferedImage image = robot.createScreenCapture(rectangle);

Color.getRGB(195, 174, 196) 的问题是它是一个 getter,没有参数。调用这个方法的方法是:

color.getRGB();

但是同样,您使用的是没有实例的实例方法,您需要做的是:

Color color = new Color(r, g, b);
color.getRGB();

The first issue is that you're accessing an instance method on the class Robot instead of an instance of robot.

just change the case and it will be fixed:

BufferedImage image = robot.createScreenCapture(rectangle);

The issue with Color.getRGB(195, 174, 196) is that it is a getter, it has no parameters. The way to call this method is:

color.getRGB();

but again, you're using accessing an instance method without an instance, what you need to do is:

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