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-12  คลาส BallG คือ Ball ที่เด้งเสมือนมีแรงโน้มถ่วง
import jlab.graphics.DWindow;

public class BallG extends Ball {
  private double gravity = 2;

  public BallG(double r, double x, double y) {
    super(r, x, y);
  }
  public double getGravity() {
    return gravity;
  }
  public void setGravity(double g) {
    gravity = g;
  }
  public void move(DWindow w) {
    dy += gravity;
    super.move(w);
  }
}
©2009 S.Prasitjutrakul