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-21  คลาส Ball3DImage วาดภาพลูกบอลจากแฟ้มภาพ
import jlab.graphics.*;

public class Ball3DImage extends Ball3D {
  private DImage image;;
  public Ball3DImage(String fn, double x, double y, double z) {
    super(10, x, y, z);
    image = new DImage(fn);
    r = image.getWidth() / 2;
  }
  public void draw(DWindow3D w3) {
    drawShadow(w3);
    w3.drawImage(image, x, y, z);
  }
  private void drawShadow(DWindow3D w3) {
    double s = y / w3.getHeight();
    w3.fillEllipse(DWindow.BLACK, x, w3.getHeight(), z,
                   2*r*s, r/2*s);
  }
}
©2009 S.Prasitjutrakul