-1
// The "Animation" class.
import java.awt.*;
import hsa.Console;

public class Animation
{
    static Console c;           // The output console


    public static void main (String[] args) throws InterruptedException
    {
        c = new Console ();


        for (int index = 0 ; index < 300 ; index += 10)
        {



            // This is the night sky     
            c.setColor (Color.black);
            c.fillRect (0, 0, 1500, 700);
            c.drawRect (0, 0, 1500, 700);

            // This is the moon 
            c.setColor (Color.white);
            c.fillOval (550, 10, 80, 90);

            // These are the stars in the background 
            c.setColor (Color.yellow);
            c.fillStar (50, 70, 20, 20);
            c.fillStar (90, 100, 20, 20);
            c.fillStar (130, 70, 20, 20);
            c.fillStar (210, 70, 20, 20);
            c.fillStar (290, 70, 20, 20);
            c.fillStar (370, 70, 20, 20);
            c.fillStar (450, 70, 20, 20);
            c.fillStar (170, 100, 20, 20);
            c.fillStar (250, 100, 20, 20);
            c.fillStar (330, 100, 20, 20);
            c.fillStar (410, 100, 20, 20);

            // This is the shooting star 
            c.fillStar (index, index, index + 20, index + 10);

            Thread.sleep (1400);




        }

        // Place your program here.  'c' is the output console
    } // main method
} // Animation class

我们正在研究计算机科学的总结,任务是利用我们在 Java 中的知识来构建一个可以运行简单动画的程序。这是我到目前为止得到的代码,问题是流星越来越大,但我希望它保持 1 号大小,你有什么建议吗?

4

2 回答 2

0

我认为这是因为你index在你的widthheight参数中使用了。我还假设这个 API 的 Javadoc 在这里。如果是这样,我会建议类似:

c.fillStar(index, index, 20, 10);
于 2013-01-20T14:37:15.290 回答
0

代替

        c.fillStar (index, index, index + 20, index + 10);

经过

        c.fillStar (index, index,  20,  10);
于 2013-01-20T14:37:24.837 回答