我刚刚开始学习Java编程,而且我一直在练习,我必须让一个圆圈成长,一个正方形成长和收缩。我的代码似乎没有错误,但形状根本没有调整大小。你能告诉我我做错了什么吗?
以防万一的更多信息:这是由uni提供的练习。我们必须在外部库中包含Shapes包。
public class Grow {
private void animateStep() {
Canvas.getCanvas().wait( 50 );
}
private void eraseObject(Object erased) {
Canvas.getCanvas().erase(erased);
}
public void animateGrowingCircle(){
Circle c = new Circle();
c.makeVisible();
for(int i=0; i <= 300 ; i++){
System.out.println("Size is " + i);
animateStep();
}
eraseObject(c);
}
public void animateGrowingThenShrinkingSquare(){
Square s = new Square();
s.makeVisible();
for (int j=0; j <= 300; j++){
System.out.println("The square is growing by " + j);
animateStep();
}
for(int k=300; k >= 0; k--){
System.out.println("The square is now shrinking by " + k);
animateStep();
}
eraseObject(s);
}
以下是测试类:
public class GrowTest {
public static void main(String[] args) throws InterruptedException {
Grow g = new Grow();
g.animateGrowingCircle();
Thread.sleep(2000);
g.animateGrowingThenShrinkingSquare();
Thread.sleep(2000);
System.exit(0);
}
}
感谢您的帮助。