-1

if statement not working for color conditions

import java.awt.AWTException;
import java.awt.Robot;

public class TestColor {
    public static void main(String [] args) throws AWTException {
        Robot Bot = new Robot();

        if(Bot.getPixelColor(1003, 185)==Bot.getPixelColor(1003, 185)) {
            System.out.println("True");
        }else {
            System.out.println("False");
        }
    }
}

and i got a result of:

False

1 Answers1

0

getPixelColor() returns a Color object, == for two objects tests if the object reference is the same, c1.equals(c2) test if the values of the object are the same (where c1 and c2 are Color objects).

Mike Kim
  • 115
  • 6