其实没必要这么麻烦
即使是在练习借口使用上
针对功能,改了点
import java.awt.*;
import java.applet.Applet;
/*
<APPLET
CODE=dbuffer.class
WIDTH=200
HEIGHT=200>
</APPLET>
*/class t1 implements Runnable
{
public boolean sto1=true;
public long cou1;
Graphics g1 = null;
Thread thread;
t1( Graphics g )
{
thread=new Thread(this,"t1");
thread.start();
g1 = g;
g1.setXORMode( Color.WHITE );
}
public void run()
{
while(sto1)
{
cou1++;
try{
Thread.sleep(100);
if(cou1>1) g1.drawString(Long.toString(cou1-1),10,10);
g1.drawString(Long.toString(cou1),10,10);
}
catch(InterruptedException e){}
}
}
}class t2 implements Runnable
{
public boolean sto2=true;
public long cou2;
Graphics g2 = null;
Thread thread;
t2( Graphics g )
{
thread=new Thread(this,"t2");
thread.start();
g2 = g;
g2.setXORMode( Color.WHITE );
}
public void run()
{
while(sto2)
{
cou2++;
try{
Thread.sleep(100);
if(cou2>1) g2.drawString(Long.toString(cou2-1),40,10);
g2.drawString( Long.toString(cou2),40,10);
}
catch(InterruptedException e){}
}
}
}public class dbuffer extends Applet
{
t1 nt1=null;
t2 nt2=null;
Thread nt3=null;
public void start()
{
t1 nt1=new t1( this.getGraphics() );
t2 nt2=new t2( this.getGraphics() );
}
}由于t1和t2一样的功能,可以只写一个,生成两个线程
可能楼主的程序里是需要两个线程完成不同的任务
所以保留了
即使是在练习借口使用上
针对功能,改了点
import java.awt.*;
import java.applet.Applet;
/*
<APPLET
CODE=dbuffer.class
WIDTH=200
HEIGHT=200>
</APPLET>
*/class t1 implements Runnable
{
public boolean sto1=true;
public long cou1;
Graphics g1 = null;
Thread thread;
t1( Graphics g )
{
thread=new Thread(this,"t1");
thread.start();
g1 = g;
g1.setXORMode( Color.WHITE );
}
public void run()
{
while(sto1)
{
cou1++;
try{
Thread.sleep(100);
if(cou1>1) g1.drawString(Long.toString(cou1-1),10,10);
g1.drawString(Long.toString(cou1),10,10);
}
catch(InterruptedException e){}
}
}
}class t2 implements Runnable
{
public boolean sto2=true;
public long cou2;
Graphics g2 = null;
Thread thread;
t2( Graphics g )
{
thread=new Thread(this,"t2");
thread.start();
g2 = g;
g2.setXORMode( Color.WHITE );
}
public void run()
{
while(sto2)
{
cou2++;
try{
Thread.sleep(100);
if(cou2>1) g2.drawString(Long.toString(cou2-1),40,10);
g2.drawString( Long.toString(cou2),40,10);
}
catch(InterruptedException e){}
}
}
}public class dbuffer extends Applet
{
t1 nt1=null;
t2 nt2=null;
Thread nt3=null;
public void start()
{
t1 nt1=new t1( this.getGraphics() );
t2 nt2=new t2( this.getGraphics() );
}
}由于t1和t2一样的功能,可以只写一个,生成两个线程
可能楼主的程序里是需要两个线程完成不同的任务
所以保留了
没必要这样子写吧!
应该这样:public class dbuffer extends Applet