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-4  โปรแกรมวาดลายเส้นด้วยเมาส์
import jlab.graphics.DWindow;
// โปรแกรมวาดลายเส้นด้วยเมาส์ 
public class Scribble {
  public static void main(String[] args) {
    DWindow w = new DWindow(160, 160);
    double x0 = 0, y0 = 0, x1, y1;
    while (true) {
      x1 = w.getMouse().getX();
      y1 = w.getMouse().getY();
      w.drawLine(x0, y0, x1, y1);
      x0 = x1; y0 = y1;
    }
  }
}
©2009 S.Prasitjutrakul