user27209652
user27209652

Reputation: 7

AutoClicker.java uses or overrides a deprecated API. Recompile with -Xlint:deprecation for details

I am trying to make an auto clicker.

I am getting this error message:

AutoClicker.java uses or overrides a deprecated API. Recompile with -Xlint:deprecation for details

Nothing I do seems to stop it. I am new to coding so I do not really know how to solve these types of problems.

I am running this on jGRASP on Windows 10.

import java.awt.*;
import java.awt.event.InputEvent;

public class AutoClicker {
    public static void main(String[] args) throws AWTException {
        wait(2500);
        for (int i = 0; i < 500; i++) {
            mouseClick();
            wait(10);
        }
    }
    public static void wait(int x) {
        try {
            Thread.sleep(x);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    public static void mouseClick() throws AWTException {
        Robot bot = new Robot();
        bot.mousePress(InputEvent.BUTTON1_MASK);
        bot.mouseRelease(InputEvent.BUTTON1_MASK);
    }
}

Upvotes: -1

Views: 94

Answers (1)

Basil Bourque
Basil Bourque

Reputation: 338566

Warning vs Error

You received a compiler warning, not a compiler error.

Warnings do not stop the compiler, while an error does. With just that warning, your code would compile and run.

Deprecation

Deprecation means that class, method, or constant is no longer recommended for use. See @Deprecated. That feature may even be removed eventually. So you should avoid that usage if at all possible.

Alternative

Fortunately, a suggested alternative is almost always provided along with the deprecation. That is so in your case.

java.awt.event.InputEvent.BUTTON1_MASK was deprecated as of Java 9. The Javadoc says:

It is recommended that BUTTON1_DOWN_MASK and getModifiersEx() be used instead

So I suppose you should change your code to this (though I am no expert on AWT or Robot, and this code is untested):

    public static void mouseClick ( ) throws AWTException
    {
        Robot bot = new Robot( );
        bot.mousePress( InputEvent.BUTTON1_DOWN_MASK );
        bot.mouseRelease( InputEvent.BUTTON1_DOWN_MASK );
    }

Solving the problem

You said:

I do not really know how to solve these types of problems.

The first step always is: RTFM, Read The Fine Manual. In Java, that means reading the Javadoc documentation for the class, method, or constant. For smaller features, follow The Java™ Tutorials by Oracle, free of cost. For larger features, read the JEP (see list). Perhaps peruse the other documentation.

Second step is to search Wikipedia for technical terms like "deprecated". You will find a wealth of technical info.

Upvotes: 2

Related Questions