J2ME learning notes (3) ----- Learn MIDLETS

zhaozj2021-02-16  83

Handling 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 the Application Management Software installed on the MIDP device. A environment for KVM and MIDLETS

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 be displayed 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 at Our Head The scroll text on the top of the screen "NOTE: YOUR PIN NUMBER HAS BEEN SENT to You at Your Mailing Address."

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 ();

}

}

}

The test results are as follows:

转载请注明原文地址:https://www.9cbs.com/read-12461.html

New Post(0)