?? threadrace.java
字號:
//import goodFrame;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.applet.Applet;
import myThread;
public class ThreadRace extends Applet implements Runnable{
myThread theRacers[];
static int racerCount=3;
Thread theThreads[],thisThread;
int numberofThreadsAtStart;
public void init(){
numberofThreadsAtStart=Thread.activeCount();
setLayout(new GridLayout(racerCount,1));
theRacers=new myThread[racerCount];
theThreads=new Thread[racerCount];
for(int x=0;x<racerCount;x++){
theRacers[x]=new myThread("Racer +"+x);
theRacers[x].resize(size().width,size().height/racerCount);
add(theRacers[x]);
theThreads[x]=new Thread(theRacers[x]);
theThreads[x].setPriority(Thread.MIN_PRIORITY+x*3);
}
}
public void start(){
for(int x=0;x<racerCount;x++)
theThreads[x].start();
thisThread=new Thread(this);
thisThread.start();
}
public void stop(){
thisThread.stop();
}
public void run(){
while(Thread.activeCount()>numberofThreadsAtStart+2){
try{
thisThread.sleep(10);
}catch(InterruptedException e){
System.out.println("thisThread was interrupted");
}
}
stop();
destroy();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -