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-41  คลาส Ball3D เขียนให้ปฏิบัติตามอินเทอร์เฟซ Comparable
import jlab.graphics.*;

public abstract class Ball3D extends BallG implements Comparable {
  protected double z, dz;

  public int compareTo(Object obj) {
    Ball3D that = (Ball3D) obj;
    if (this.z == that.z) return 0;
    if (this.z < that.z) return -1;
    return 1;
  }  
  protected Ball3D(double r, double x, double y, double z) { ... }
  public void move(DWindow3D w3) { ... }
  protected void drawShadow(DWindow3D w3) { ... }
  public abstract void draw(DWindow3D w3);
}
©2009 S.Prasitjutrakul