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-2  คลาส ColoredBall เขียนจากคลาส Ball ให้ตั้งสีได้
import jlab.graphics.DWindow;
public class ColoredBall extends Ball {
  private int color;
  public ColoredBall(double r, double x, double y) {
    this(r, x, y, DWindow.BLACK);
  }
  public ColoredBall(double r, double x, double y, int color) {
    super(r, x, y);
    this.color = color;
  }
  public void setColor(int c) {
    this.color = c;
  }
  public int getColor() {
    return this.color;
  }
  public void draw(DWindow w) {
    w.fillEllipse(this.color, super.x,super.y,2*super.r,2*super.r);
  }
}
©2009 S.Prasitjutrakul