J2ME Learning Notes (3) ----- Learning MIDlets Source Processing MIDlets
1. MIDlet is a MIDLET app that uses MIDP features and CLDC configuration
1) .MIDLET is a Java class file packaged into a JAD (Java descriptor) file 2). MIDlet runs on Application Management Software (Application Management Software AMS) installed on the MIDP device. AMS provides KVM and MIDLETS environments 3) .MIDlet is used in handheld devices that support CLDC and MIDP.
2. MIDlet lifecycle (Figure)
3. Develop MIDlets instances
1). Task Statement ----- SaveMymoney Mobile Bank Application The message to display on the top of "Welcome to Savemoney Bank!", There is a display message on the top of the screen "Welcome to the world of mobile banking!" Scroll text; the message to display on the second screen is "dear customer, you can view Your PERSONAL ACCOUNT INFORMATION BY Entering Your Pin Number and sending it to the number 9002. if you have not received the Pin Number, please contact us ATUR Head Office. "There is a display message at the top of the screen" NOTE: YOUR PIN NUMBER HAS BEEN SENT to You At Your Mailing Address. "scrolling text
2) The code is as follows ----- import javax.microedition.midlet. *;
Import javax.microedition.lcdui. *;
/ / Need to implement the CommandListener interface in the LCDUI class
Public Class MB Extends Midlet Imtributes CommandListener
{
// Use Display class management display and user input
Display display;
Form Form1;
Form form2;
/ / Define two scroll bars Ticker1, Ticker2
Ticker Ticker1;
Ticker Ticker2;
Static Final Command Okcommand = New Command ("Info", Command.ok, 1);
Static final command backcommand = new command ("back", command.back, 0);
Static Final Command EXITCOMMAND = New Command ("EXIT", Command.Stop, 2);
Public MB ()
{
}
Public void startapp () throws MidletStateChangeException
{
Ticker1 = New Ticker ("Welcome to The World of Mobile Banking!");
Ticker2 = New Ticker ("NOTE: YOUR PIN NUMBER HAS BEEN SENT To You At Your Mailing Address.");
Display = display.getdisplay (this);
Form1 = new form ("SavemyMoney");
Form2 = New form ("Customer Care");
StringItem strItem = new StringItem ( "Welcome to SaveMyMoney Bank!", ""); StringItem strItem1 = new StringItem ( "Dear Customer,", "You can view your personal account information by entering your PIN number and sending it to the number 9002 . If you have not received The PIN Number, please contact US AT Our Head Office. ");
Form1.Append (stritem);
Form2.append (stritem1);
// Add command to the screen, the left soft key of the first screen is exit, the right soft key is OK
Form1.addcommand (EXITCOMMAND);
Form1.addcommand (OkCommand);
//monitor
Form1.setCommandListener (this);
Form1.setticker (Ticker1);
/ / Set the current display of the home screen for Form1
Display.SetCurrent (Form1);
}
Public void pauseApp ()
{
}
Public void destroyApp (Boolean Unconditional)
{
NotifyDestroyed ();
}
Public void showform1 ()
{
Form1.addcommand (EXITCOMMAND);
Form1.addcommand (OkCommand);
Form1.setCommandListener (this);
Display.SetCurrent (Form1);
}
Public void showform2 ()
{
Form2.addcommand (EXITCOMMAND);
Form2.addcommand (backcommand);
Form2.setCommandListener (this);
Form2.setticker (Ticker2);
Display.SetCurrent (Form2);
}
Public Void CommandAction (Command CMD, Displayable Displayable)
{
String label = cmd.getlabel ();
Label.equals ("exit"))
{
/ / Call the action of undo MIDlet and exit this app
DESTROYAPP (TRUE);
}
ELSE IF (Label.equals ("back"))
{
// Go Back to Form1
Showform1 ();
}
Else
{
Showform2 ();
}
}
}