Figure geometriche in movimento


Ball.java

import java.awt.*;

public class Ball extends java.applet.Applet implements Runnable {
  Thread runner;
  int x,y;

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

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

  public void run() {
    int i=0;

    for(x=0; x<=255; x++) {
      y=x;

      repaint();
      try { Thread.sleep(100); }
      catch( InterruptedException e ) { }
    }
  }

  public void paint(Graphics g) {
    g.fillOval(x,y,20,20);
  }
}