Java get color of pixel LIVE -


i have problem finding current color under cursor.

my code:

import java.awt.color; import java.awt.mouseinfo; import java.awt.point; import java.awt.pointerinfo; import java.awt.robot;  public class test {     public static void main(string[] args) throws exception {         pointerinfo pointer;         pointer = mouseinfo.getpointerinfo();         point coord = pointer.getlocation();          robot robot = new robot();         robot.delay(2000);          while(true) {             coord = mouseinfo.getpointerinfo().getlocation();                    color color = robot.getpixelcolor((int)coord.getx(), (int)coord.getx());             if(color.getgreen() == 255 && color.getblue() == 255 && color.getred() == 255) {                 system.out.println("white found");             }             robot.delay(1000);         }     } } 

when run it, when hold mouse on gray area, getting “white found white found” message.

what can problem? can guys test if not work also?

added picture: holding cursor on eclipse gray area getting “white found” message.

enter image description here

i think problem using getx twice instead of getx , gety

color color = robot.getpixelcolor((int)coord.getx(), (int)coord.getx()) 

should be

color color = robot.getpixelcolor((int)coord.getx(), (int)coord.gety()) 

Comments