J2ME的Thread使用
|
|
Author: 一滴蔚蓝色 | Date: 2007-08-26 |
View: 2084 |
开发技术 - 新手上路 | Digg:
0
|
|
Thread 可以让我们的程序看起来同时间作一个以上的事情,范例如下: //MyThread.java public class MyThread extends Thread { boolean exit = false; char printchar; public MyThread(char c) { printchar = c; } public void run() { while (!exit) { System.out.print(printchar); System.out.flush(); try { Thread.sleep(1000); } catch (Exception e) {} } } } //ThreadTest.java import javax.microedition.midlet.*; import javax.microedition.lcdui.*; public class ThreadTest extends MIDlet { MyThread mt1; MyThread mt2; public ThreadTest() { } public void startApp() { mt1 = new MyThread('A'); mt1.start(); mt2 = new MyThread('B'); mt2.start(); } public void pauseApp() { } public void destroyApp(boolean unconditional) { mt1.exit = true; mt1 = null; mt2.exit = true; mt2 = null; } } 执行结果: 更多阅读: |
|
| 最近更新 ( 2008-11-29 ) |
尚无评论发表