0

So part of my program requires me to get the RGB value of wherever the mouse is above IN THE JFRAME. It's not working though, and I'm not entirely sure if the x,y coordinates im using for getPixelColor is giving me the color of those coordinates within the screen instead of the jframe. What would be the best way to get the color of where the mouse is within the Jframe?

        public void mouseMoved(MouseEvent e) {
        // check the color of the pixel the the mouse is over, and
        // go to the next level, or show the game over screen

    Robot robot = null;
    try {
        robot = new Robot();
    } catch (AWTException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }


        int xcord = e.getX();
        int ycord = e.getY();
        Color color = robot.getPixelColor(xcord, ycord);

        System.out.println(color);
 }
  • For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete and Verifiable Example). BTW - what is the end purpose of this? – Andrew Thompson May 25 '14 at 00:32
  • 2
    [`Zoom`](http://stackoverflow.com/a/3742841/230513) is an example that displays the color as a tool tip. – trashgod May 25 '14 at 00:38

0 Answers0