frame.addMouseListener (new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
int x = e.getX();
int y = e.getY();
//Point lastPoint = e.getPoint();
System.out.println("Mouse Position = " + x + " " + y);
//System.out.println("Shape Position = " + + " " + y);
try {
Color color = new Robot().getPixelColor(x, y);
System.out.println("Red = " + color.getRed());
System.out.println("Green = " + color.getGreen());
System.out.println("Blue = " + color.getBlue());
}
catch (AWTException e1) {
e1.printStackTrace();
}
}
Hello, I tried getting color of the pixel my mouse clicks on. It works perfectly fine with the JFrame on the top left of the screen, however, right after I move the window, the colors are all thrown off.