如现在applet里
public class A extends java.applet.Applet
               implements Runnable
{
     Thread t1 = null;
     Thread t2 = null;     public void start()
     {
         t1 = new Thread(this);
         ?? //t2 = new Thread(this);      
     }     public void run()
     {
     }      
}假如t1 t2线程都要向WEB显示 就是说都要调用paint()但是它们的功能不一样 就不能用同一个run() 如果再定义一个applet的派生类那就不是在一个applet里起多个线程了,应该怎么定义

解决方案 »

  1.   

    是这样吗public class Test extends java.applet.Applet 
                       implements Runnable
    {    
        /** Initialization method that will be called after the applet is loaded
         *  into the browser.
         */
        int num;
        Thread t1 = null;
        Thread t2 = null;
        public void init() 
        {
            // TODO start asynchronous download of heavy resources
        }
       public void start()
       {
           t1 = new Thread(this);
           t2 = new Thread(new A());
           t1.start();
           t2.start();
       }
        // TODO overwrite start(), stop() and destroy() methods
       
       public void paint(Graphics g)
       {
           g.drawString("Hello", 10+num,10);
       }
        public void run()  
        { 
            while(true)
            {
                repaint();
                num++;
                try{t1.sleep(500);}
                catch(InterruptedException e)
                {}
            }
        }    class A implements Runnable
        {
            public void run()
            {
                while(true)
                {
                    if (num%10 == 0)
                    {
                        t1.stop();
                    }
                }
            }
        }
    }
      

  2.   

    可是这两个线程只能调用一个paint() 比如我需要调用t1时在WEB里显示T1 STARTS 在调用t2时在WEB里显示T2 STARTS 怎么办呢