I have a sort of animation going on in which a rectangle is increasing and decreasing in size........what i want to do here is detect the color of a particular location through Robot() class but its not happening..........why?? I also want to know if Robot() can be used outside try or without main() class.
//<applet code=ctry.java width=500 height=500></applet>
import java.awt.*;
import java.applet.Applet;
import java.awt.AWTException;
public class ctry extends Applet implements Runnable{
Thread d=null;
int l=0,t=0,i=250,j=250;
Color color=null;
public void init(){
setBackground(Color.red);
}
public void start(){
d=new Thread(this);
d.start();
}
public void run(){
System.out.println("in run");
try{
Robot robo=new Robot();
System.out.println("after robo");
while(true){
System.out.println("in while");
repaint();
color=robo.getPixelColor(i,j);
System.out.println("Red = " + color.getRed());
l+=10;
t+=10;
d.sleep(100);
if(t>=225)
{t=0;}
if(l>=225)
{l=0;}
}
}
catch(Exception e)
{}
}
public void paint(Graphics g)
{
System.out.println("in paint");
g.setColor(Color.blue);
g.fill3DRect(225,225,l*2,t*2,true);
}
public void destroy()
{}
}