扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
//文件名: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("手电筒状态:","打开");
this.append(si);
display = Display.getDisplay(lm);
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);
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) {
//关闭
if (c == cmdExit) {
// stop the MIDlet
LightMIDlet.quitApp();
}
//打开
if(c == cmdOpen){
display.flashBacklight(1000000);
si.setText("打开");
}
if(c == cmdClose){
display.flashBacklight(0);
si.setText("关闭");
}
}
}
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者