如现在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里起多个线程了,应该怎么定义
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();
}
}
}
}
}