RunnableGBall

Retired DISLab
이동: 둘러보기, 찾기
public class RunnableGBall extends GBall implements Runnable {
 
	/** Creates a new ball with radius r centered at the origin */
	public RunnableGBall(double r) {
		super(r);
	}
 
	public void setEnclosureSize(double width, double height) {
		enclosureWidth = width;
		enclosureHeight = height;
	}
 
	public void setVelocity(double vx, double vy) {
		dx = vx;
		dy = vy;
	}
 
	@Override
	public void run() {
		// TODO Auto-generated method stub
		while (true) {
			advanceOneTimeStep();
			pause(PAUSE_TIME);
		}
	}
 
	private void advanceOneTimeStep() {
		double bx = getX();
		double by = getY();
		double r = getWidth() / 2;
		if (bx < r || bx > enclosureWidth - r) dx = -dx;
		if (by < r || by > enclosureHeight - r) dy = -dy;
		move(dx, dy);
	}
 
	/* Private constants */
	private static final int PAUSE_TIME = 20;
 
	/* Private instance variables */
	private double enclosureWidth;
	private double enclosureHeight;
	private double dx;
	private double dy;
}
개인 도구
이름공간
변수
행위
둘러보기
구성원
연구
연구실
기타
도구모음
인쇄/내보내기