六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 17|回复: 0

Nokia系列手机上的一个手电筒J2ME程序(附源代码)

[复制链接]

升级  0.4%

326

主题

326

主题

326

主题

探花

Rank: 6Rank: 6

积分
1008
 楼主| 发表于 2013-2-4 20:18:11 | 显示全部楼层 |阅读模式
Nokia系列手机上的一个手电筒程序(附源代码)
作者:陈跃峰
出自:http://blog.csdn.net/mailbomb
       在晚上的楼梯上,没有灯时,很多人需要用手机来照明,所以就有了这个简单的手电筒程序。程序利用的是Nokia UI API中提供的功能实现,程序在Nokia 6020上测试通过。具体的源代码如下:
//文件名:LightMIDlet.java
package light;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class LightMIDlet extends MIDlet {
  static LightMIDlet instance;
  LightForm displayable = new LightForm();
  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.*;
import com.nokia.mid.ui.DeviceControl;
public class LightForm extends Form implements CommandListener {
  StringItem si;
  Command cmdOpen;
  Command cmdClose;
  Command cmdExit;
  public LightForm() {
    super("手电筒");
    si = new StringItem("手电筒状态:","打开");
    this.append(si);
    cmdOpen = new Command("打开",Command.OK,1);
    this.addCommand(cmdOpen);
    cmdClose = new Command("关闭",Command.CANCEL,1);
    this.addCommand(cmdClose);
    cmdExit = new Command("退出",Command.EXIT,1);
    this.addCommand(cmdExit);
    setCommandListener(this);
    DeviceControl.setLights(0,100);
  }
  public void commandAction(Command c, Displayable d) {
    //关闭
    if (c == cmdExit) {
      // stop the MIDlet
      LightMIDlet.quitApp();
    }
    //打开
    if(c == cmdOpen){
      DeviceControl.setLights(0,100);
      si.setText("打开");
    }
    if(c == cmdClose){
      DeviceControl.setLights(0,0);
      si.setText("关闭");
    }
  }
}

未经允许,严禁转载!
  
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表