j2me多线程的应用实例2014-10-20 16:53:10
( 还没有投票,继续加油! )
j2me多线程的应用实例:
import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Form; import javax.microedition.lcdui.StringItem; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class twoStrings extends MIDlet { Display display; Form form; public String promote = ""; StringItem s1 = new StringItem("string1", "" + promote); StringItem s2 = new StringItem("string1", "" + promote); public twoStrings() { } protected void destroyApp(boolean arg0) throws MIDletStateChangeException { } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { display = Display.getDisplay(this); form = new Form(""); form.append(s1); form.append(s2); display.setCurrent(form); Thread1 th1 = new Thread1(); th1.start(); Thread2 th2 = new Thread2(); new Thread(th2).start(); } class Thread1 extends Thread { int i = 1; public void run() { while (true) { promote = Integer.toString(i); i++; s1.setText(promote); try { Thread.sleep(1000); } catch (Exception e) { } } } } class Thread2 implements Runnable { int i = 1; public void run() { while (true) { promote = Integer.toString(i); i++; s2.setText(promote); try { Thread.sleep(2000); } catch (Exception e) { } } } } }
上一篇:j2me Socket通信例子
下一篇:Android删除短信