Flashlight on midp2.0 mobile phoneProgram(AppendixCode)
Author: Chen yuefeng
From: http://blog.csdn.net/mailbomb
You can run the flashlight program on all mobile phones that support midp2.0. The principle of the program is to use the Display object to control the background of the mobile phone. In this series of mobile phones, only the function of flashing the background light can be realized. The implementation code is as follows:
// File name: 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. policydestroyed ();
Instance = NULL;
}
}
// File name: lightform. Java
Package light;
Import javax. microedition. lcdui .*;
Public class lightform extends form implements commandlistener {
Stringitem Si;
Command cmdopen;
Command invocation close;
Command cmdexit;
Display display;
Public lightform (lightmidlet lm ){
Super ("Flashlight ");
SI = new stringitem ("Flashlight status:", "open ");
This. append (SI );
Display = display. getdisplay (LM );
Cmdopen = new command ("open", command. OK, 1 );
This. addcommand (cmdopen );
Closing close = new command ("close", command. Cancel, 1 );
This. addcommand (writable close );
Cmdexit = new command ("quit", command. Exit, 1 );
This. addcommand (cmdexit );
Setcommandlistener (this );
Boolean B;
B = display. flashbacklight (1000000 );
If (B = false ){
Alert = new alert ("Flashlight", "your mobile phone does not support this function! ", Null, alerttype. info );
Alert. setTimeout (3000 );
Display. setcurrent (alert );
}
}
Public void commandaction (command C, displayable d ){
// Close
If (C = cmdexit ){
// Stop the MIDlet
Lightmidlet. quitapp ();
}
// Open
If (C = cmdopen ){
Display. flashbacklight (1000000 );
Si. settext ("open ");
}
If (C = closing close ){
Display. flashbacklight (0 );
Si. settext ("close ");
}
}
}