Nokia3100的手电筒

Nokia3100居然没有提供手电筒的功能,黑暗中实在是不方便。
前一段刚看了J2ME的开发,Nokia UI API v1.0里提供了setLights(int num, int level) 方法,于是就写了个手电筒的程序放在自己手机上用,呵呵。。。代码如下:

import  javax.microedition.lcdui. * ;
import  javax.microedition.midlet. * ;
import  com.nokia.mid.ui.DeviceControl;

/**
 *
 * 
@author Autumn
 
*/

public   class  Light  extends  MIDlet  implements  CommandListener  {
    
private Display display = null;
    
private Command onCommand  = new Command("", Command.OK, 1);
    
private Command offCommand = new Command("", Command.OK, 1);
    
private Command exitCommand = new Command("退出", Command.EXIT, 1);
    
private Form form1;
    
private StringItem si;
    
/** Creates a new instance of Light */
    
public Light() {
        form1 
= new Form("手电筒");
        si 
= new StringItem("手电筒状态:","");
    }

    
    
protected void startApp() throws MIDletStateChangeException {
        
if(display == null)
            display 
= Display.getDisplay(this);
        form1.append(si);
        form1.addCommand(exitCommand);
        lights(
100, offCommand,"");
    }

    
    
protected void pauseApp() {
        
    }

    
    
protected void destroyApp(boolean unconditional) {
        notifyDestroyed();
    }

    
    
public void commandAction(Command cmd, Displayable displayable) {
        
//退出
        if (cmd == exitCommand) {
            
// stop the MIDlet
            destroyApp(true);            
        }

        
//打开
        if(cmd == onCommand){
            form1.removeCommand(onCommand);
            lights(
100, offCommand,"");
        }

        
//关闭
        if(cmd == offCommand){
            form1.removeCommand(offCommand);
            lights(
0, onCommand,"");
        }

    }

    
    
public void lights(int level, Command cmd, String s) {
        si.setText(s);
        DeviceControl.setLights(
0, level);
        form1.addCommand(cmd);
        form1.setCommandListener(
this);
        display.setCurrent(form1);
    }

}
 
另外, com.nokia.mid.ui.DeviceControl还提供了闪光和振动的api:
Method Summary
static voidflashLights(long duration)
          Temporarily flashes the lights for a specific length of time given as milliseconds in duration parameter.
static voidsetLights(int num, int level)
          Activates and deactivates the lights on the device.
static voidstartVibra(int freq, long duration)
          Activates vibration for a given length of time and frequency.
static voidstopVibra()
          Stops any vibration.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值