3. ทำซ้ำ ๆ

The Camtasia Studio video content presented here requires JavaScript to be enabled and the latest version of the Macromedia Flash Player. If you are you using a browser with JavaScript disabled please enable it now. Otherwise, please update your version of the free Flash Player by downloading here.

 
รหัสที่ 3-8  โปรแกรมแสดงลูกบอลสีดำเคลื่อนที่
import jlab.graphics.DWindow;
// โปรแกรมแสดงลูกบอลสีดำเคลื่อนที่ 
public class MovingBall {
  public static void main(String[] args) {
    DWindow w = new DWindow(200, 100);
    double x = 70, y = 0;
    double dx = 4, dy = 3;
    while (true) {
      x = x + dx;
      y = y + dy;
      w.fade(0.3);
      w.fillEllipse(w.BLACK, x, y, 20, 20);
      w.sleep(50);
    }
  }
}
©2009 S.Prasitjutrakul