怎么动起来感觉不自然呢?
import java.awt.*;import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
class Snake extends Frame
{
Vector snakelength=new Vector(1);
Snake()
{
this.setSize(300,300);
this.show();
}
public void paint(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
float x=210,y=220;
int i=0;
for(i=0;i<5;i++)
{
snakelength.addElement(new Rectangle2D.Float(x,y,10,10));
g2.fill((Rectangle2D.Float)snakelength.elementAt(i));
//g2.setColor(Color.black);
x+=10;
}
while(true)
{
try{Thread.sleep(200);}
catch(InterruptedException e){return;}
g2.clearRect(0,0,300,300);
snakelength.removeElement(snakelength.size()-1);
x-=10;
snakelength.insertElementAt(new Rectangle2D.Float(x,y,10,10),0);
for(i=0;i<5;i++)
{
g2.fill((Rectangle2D.Float)snakelength.elementAt(i));
}
}
}
}
public class SnakeMain
{
public static void main(String args[])
{
Snake snake=new Snake();
}
为什么动起来感觉特生硬,不自然呢?