2013-01-20 47 views
-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尺寸,你有什么建议吗?做简单移动动画的好方法?

回答

0

我认为这是因为您在使用widthheight参数中的index。我也假设这个API的Javadoc是here。如果是的话,我建议是这样的:

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

这一工程谢谢更换

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

! –

0

通过

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