Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

getPixelColor Question

807597Jun 21 2005 — edited Jun 22 2005
I 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)
{
}
.........
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2005
Added on Jun 21 2005
2 comments
127 views