title: How to use robot class
body: <p>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.</p>
  
  <pre><code>//&lt;applet code=ctry.java width=500 height=500&gt;&lt;/applet&gt;
  
  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&gt;=225)
         {t=0;}
        if(l&gt;=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()
  {}
  }
  </code></pre>