title: Java get color of pixel LIVE
body: <p>I have a problem with finding the current color under the cursor.</p>
  
  <p>My code:</p>
  
  <pre><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 &amp;&amp; color.getBlue() == 255 &amp;&amp; color.getRed() == 255) {
                  System.out.println("WHITE FOUND");
              }
              robot.delay(1000);
          }
      }
  }
  </code></pre>
  
  <p>When I run it, even when I hold my mouse on the gray area, I am getting “WHITE FOUND WHITE FOUND” message.</p>
  
  <p>What can be the problem? Can you guys test if it does not work for you also?</p>
  
  <p>Added Picture: I am holding my cursor on Eclipse gray area but getting “WHITE FOUND” message.</p>
  
  <p><img src="https://i.stack.imgur.com/YtAg0.png" alt="enter image description here"></p>