
import java.awt.*;
import javax.swing.*;



  public class Anim extends JApplet implements Runnable {
   
   Display disegno;
   Thread animazione;
   int x,y,r;
   
   public void init() {

     disegno = new Display();
     setContentPane(disegno);
     x = 0; y=10; r=20;
       }

   public void start() {
    if (animazione == null) {
        animazione = new Thread(this);
        animazione.start();
    }
   }

  public void stop() {
     if (animazione != null) {
       animazione = null;
     }
   }

   public void run() {
    while(true) {
      for (x = r; x <= disegno.getSize().width ; x=x+1) {
        disegno.repaint();
        try { Thread.sleep(100);}
       catch (InterruptedException e) { }
 }
 }
 }
   class Display extends JPanel{

    public void  paintComponent(Graphics g) {
      super.paintComponent(g);
      g.setColor(Color.red);
      g.fillOval(x,y,2*r,2*r);
   }
}
}
