从applet菜单调用stop并在appletviewer中重启之间的区别

时间:2013-08-26 12:30:32

标签: java appletviewer

 i have an animation program using threads and applet.

当我从appletviewer程序中的applet菜单调用stop选项时工作正常,但是当我按重启时,它的工作有一些异常。在第34行调用restart时,线程不会从while循环中出来

   class saver
    {
    .


     .
        public void run()
        {
        System.out.println("run "+Thread.currentThread().getName());
         func();
        System.out.println("out of synchronized block");
        }
        synchronized public void func()
        {
        int i;
        while(running)
        {
        for(i=0;i<4;i++)
        {
        gap[i]+=10;
        if(gap[i]==360)
        gap[i]=0;
        System.out.println(Thread.currentThread().getName());
        calc(gap[i],400,i%2==0?(byte)1:(byte)-1);
        yb[i]=(int)(y)+yc;
        xb[i]=(int)(x)+xc;
      }
        repaint();
         try                   
          {                 
           Thread.sleep(1000);          
         }              
        catch(Exception e)
        {}
         }
         System.out.println("out of while in synchronized block");//not being printed
        } 

0 个答案:

没有答案