44 j2me多线程的应用实例 - 雪炭网

j2me多线程的应用实例2014-10-20 16:53:10

( 还没有投票,继续加油! )
分享:
31.3K

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) {
        }
      }
    }
  }
}






头像

snowcoal
  • j2me
  • 多线程

本文标签:

j2me多线程

收藏到我的私密空间

标题:j2me多线程的应用实例

作者:柳岸花明

你暂未登录,请登录后才可收藏至您的私密空间 确认取消
雪炭网

键盘操作 更便捷 -雪炭网雪中送炭-乐趣无限

如果本站的内容有幸帮助到了您,建议您了解一下当页的广告内容哦,我们的进步离不开您的支持,Thank you~