有关于JAVA的动画的一题,下面是画一个带填充色的矩形并让它在屏幕上从左向右走动。不知道程序哪里有问题,麻烦各位指点。
import java.applet.Applet;
import java.awt.*;
public class juxing extends Applet implements Runnable{
  Image im;
  Thread t=null;
  public void init(){
    setBackground(Color.white);
   }
  public void start(){
   Thread t=new Thread(this);
   t.start();
   }
public void run(){
      try{
      while(true){
      t.sleep(1000);
      repaint();
       }
      }catch(InterruptedException e){}
 }public void paint(Graphics g){
 
 for(int i=0;i<240;i++){
   g.fillRect(i,80,70,40);
  g.drawImage(im,i,80,this);
}
   }
}

解决方案 »

  1.   

    以上程序执行对应的test.html之后没有任何反应。
    test.html的内容如下:
    <applet code="juxing.class" width="500" height="500"/>test.html和juxing.class位于同一个目录下。
      

  2.   

    帮你改好了.test.html要这样写
    <applet   code="juxing.class"   width="300"   height="300">
    </applet>import   java.applet.Applet; 
    import   java.awt.*;
    public   class   juxing   extends   Applet   implements   Runnable{
    int i; 
        Image   im; 
        Thread   t=null; 
        public   void   init(){
            setBackground(Color.white); 
          } 
        public   void   start(){ 
          t=new   Thread(this); 
          t.start(); 
          } 
    public   void   run(){ 
                while(true)
    {
    try
    {
    Thread.currentThread().sleep(1000);
    i=i+10;
    if(i>300)
    i=0;
    repaint();
    }
    catch (InterruptedException e)
    {
    throw new RuntimeException(e);
    }
    }
      } public   void   paint(Graphics   g){
          g.fillRect(i,80,70,40); 
          g.drawImage(im,i,80,this); 
          } 
    }