9. สร้างใหม่จากเก่า

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.

 
รหัสที่ 9-13  คลาส Ball3D คือ BallG ที่เด้งในห้อง
import jlab.graphics.DWindow;

public class Ball3D extends BallG {
  public double z, dz;

  public Ball3D(double r, double x, double y, double z) {
    super(r, x, y);
    this.z = z;
    dz = -5 + (10 * Math.random());
  }
  public void draw(DWindow3D w3) {
    w3.fillEllipse(DWindow.BLACK, x, y, z, 2*r, 2*r);
  }
  public void move(DWindow3D w3) {
    super.move(w3);
    z += dz;
    if (z <= 0 || z >= w3.getDepth()) dz = -dz;
    z = Math.min(Math.max(z, 0), w3.getDepth());
  }
}
©2009 S.Prasitjutrakul