国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

MIDP2.0手機上手電筒程序的實現(xiàn)

2019-11-18 19:09:43
字體:
供稿:網(wǎng)友

  可以在所有支持MIDP2.0版本的手機上運行的手電筒程序。程序?qū)崿F(xiàn)的原理是:利用Display對象來實現(xiàn)對于手機背景等的控制,在該系列的手機中只能實現(xiàn)閃爍背景燈的功能。

  實現(xiàn)代碼如下:
//文件名:LightMIDlet.java

package light;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class LightMIDlet extends MIDlet {
  static LightMIDlet instance;
  LightForm displayable = new LightForm(this);
  public LightMIDlet() {
    instance = this;
  }

  public void startApp() {
    Display.getDisplay(this).setCurrent(displayable);
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }

  public static void quitApp() {
    instance.destroyApp(true);
    instance.notifyDestroyed();
    instance = null;
  }

}

 

//文件名:LightForm.java

package light;

import javax.microedition.lcdui.*;

public class LightForm extends Form implements CommandListener {
  StringItem si;
  Command cmdOpen;
  Command cmdClose;
  Command cmdExit;
  Display display;
  public LightForm(LightMIDlet lm) {
    super("手電筒");
    si = new StringItem("手電筒狀態(tài):","打開");
    this.append(si);

    display = Display.getDisplay(lm);

    cmdOpen = new Command("打開",Command.OK,1);
    this.addCommand(cmdOpen);

    cmdClose = new Command("關(guān)閉",Command.CANCEL,1);
    this.addCommand(cmdClose);

    cmdExit = new Command("退出",Command.EXIT,1);
    this.addCommand(cmdExit);

    setCommandListener(this);

    boolean b;

    b = display.FlashBacklight(1000000);

    if(b == false){
      Alert alert = new Alert("手電筒","您的手機不支持該功能!",null,AlertType.INFO);
      alert.setTimeout(3000);
      display.setCurrent(alert);
    }
  }

  public void commandAction(Command c, Displayable d) {
    //關(guān)閉
    if (c == cmdExit) {
      // stop the MIDlet
      LightMIDlet.quitApp();
    }
    //打開
    if(c == cmdOpen){
      display.flashBacklight(1000000);
      si.setText("打開");
    }

    if(c == cmdClose){
      display.flashBacklight(0);
      si.setText("關(guān)閉");
    }
  }

}


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 宁陵县| 永定县| 博湖县| 汽车| 阜平县| 东光县| 恩平市| 永济市| 喜德县| 娄烦县| 菏泽市| 梓潼县| 乐东| 鞍山市| 盐城市| 兴和县| 郸城县| 寻乌县| 镇宁| 大足县| 土默特右旗| 江川县| 嘉兴市| 南开区| 日照市| 德令哈市| 无棣县| 溆浦县| 定日县| 达尔| 呼伦贝尔市| 福安市| 庄浪县| 祁阳县| 甘谷县| 辉县市| 米林县| 城市| 苍山县| 金寨县| 木里|