继承Thread类的子类,可以覆盖Thread类的run()方法,run()方法被看做线程的起点。当要运行Thread时,需要调用start()来执行线程。MIDP Thread API示例6-11中说明线程的应用方法是:
class PrimeThread extends Thread{
long minPrime;
PrimeThread(long minPrime){
This.minPrime=minPrime;
}
public void run (){
…
}
}
本段为线程的基本编写方法。但是此时这段内容不会真正执行,需要调用下列方法才会执行。
PrimeThread p = new PrimeThead(143);
p.start();
示例6-11
/×
Thread线程执行动态画面调用方法
×/
import javax.microedition.midlet.×;
import javax.microedition.lcdui.×;
public class threadDemo1 extends MIDlet
{
Display display;
//声明图片显示对象
canvasThread canvasthread;
public threadDemo1()
{
canvasthread=new canvasThread();
display=Display.getDisplay(this);
}
public void startApp()
{
display.setCurrent(canvasthread);
}
public void pauseApp(){}
public void destroyApp(boolean unconditional){}
class canvasThread extends Canvas
{
int gameaction=0;
int view=0;
//声明一个线程
goCanvas gocanvas;
boolean again;
Image[ ] cloudImage;
Image[ ] sunImage;
public canvasThread()
{
try{
//建立全部云朵图片数组
[1] [2] [3] 下一页