getPixelColor Question
807597Jun 21 2005 — edited Jun 22 2005I have a Canvas in a JFrame, with shapes of different colors painted on it.
I want to get the color of the pixel on which the user clicks.
If it is white, i want to print "test" on the screen.
My code is the following,but it doesn't seem to work properly.
Even if you click on non-white shape "test" is printed.
public class Theater extends Canvas
{
......
class ActionList extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
if(e.getClickCount() == 1)
{
int c=e.getX();
int d=e.getY();
try
{
Robot myRobot = new Robot();
if(myRobot.getPixelColor(c, d).equals(Color.white))
System.out.println("test");
}
catch(AWTException awtx)
{
}
.........