J2ME Learning Notes (IV) ----- Developing MIDlets with specific MIDP API

zhaozj2021-02-16  80

Develop MIDLETS with specific MIDP API

1. Specific classes and interfaces in MIDP

1) javax.microedition.midlet ---- is the innermost package, only one MIDLET class, provides basic feature expenses for MIDP applications

2) javax.microedition.io ----- includes httpConnection interface, through this interface, MIDlet device can access data in the Web

3) javax.microedition.lcdui (Liquid Crystal Display User Interface LCD Display User Interface) ----- Provide support for the GUI component, with the same functionality as java.awt, the class and interface in the javax.microedition.lcdui package Applicable to the handheld device with a small screen.

4) javax.microedition.rms (Record Management System) ----- Support for different class and interfaces of the database system, then store and retrieve the data used by MIDlet

2. An example:

1) Task Statement ----- SaveMymoney Bank's mobile application system first screen displays welcome messages, the current date, current time, total memory, and free memory should be displayed on the second screen

2) The implementation code is as follows:

Import javax.microedition.midlet. *;

Import javax.microedition.lcdui. *;

Import java.util. *;

Public Class MB Extends Midlet Imtributes CommandListener

{

Display display;

Form Form1;

Form form2;

Ticker Ticker1;

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

{

Display = display.getdisplay (this);

Ticker1 = New Ticker ("Welcome to The World of Mobile Banking!");

Form1 = new form ("SavemyMoney");

Form2 = new form ("information");

Calendar Calendar1 = Calendar.getInstance ();

INT DATE = Calendar1.Get (Calendar.Mont);

String Date1 = integer.tostring (Calendar1.Get (Calendar.day_Of_Month) ""

Integer.toString (Calendar1.Get (Calendar.Year);

String time = integer.tostring (Calendar1.Get (Calendar.Hour_Of_DAY)) ":"

Integer.toString (Calendar1.Get (Calendar.minute)) ":" Integer.tostring (Calendar1.Get (Calendar.Second);

Runtime runmemory = runtime.getRuntime ();

String Total_Memory = long.toString (runmemory.totalmemory);

String free_memory = long.tostring (runmemory.freeMemory ());

String Month = "0";

Switch (date)

{

Case 0: Month = "January"; Break;

Case 1: Month = "february"; Break;

Case 2: Month = "march";

Case 3: Month = "April"; Break;

Case 4: Month = "May"; Break;

Case 5: Month = "June"; Break;

Case 6: Month = "july"; Break;

Case 7: Month = "August"; Break;

Case 8: Month = "september"; Break;

Case 9: Month = "October"; Break;

Case 10: Month = "November"; Break;

Case 11: Month = "decEmber";

}

StringItem strItem = New StringItem ("Welcome to Savemoney Bank!", "")

Form1.Append (stritem);

FORM2.APpend (New StringItem ("," Date: " MONTH ", ");

Form2.append (date1);

Form2.Append (New StringItem ("," Time: " Time));

FORM2.APpend (New StringItem ("," Total Memory: " Total_Memory);

FORM2.APpend (New StringItem ("", "Free Memory:" free_memory);

Form1.addcommand (EXITCOMMAND);

Form1.addcommand (OkCommand);

Form1.setCommandListener (this);

Form1.setticker (Ticker1);

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

Display.SetCurrent (Form2);

}

Public void CommandAction (Command C, Displayable D)

{

String label = c.getlabel ();

Label.equals ("exit"))

{

DESTROYAPP (TRUE);

}

ELSE IF (Label.equals ("back"))

{

// Go Back to Form1

Showform1 ();

}

Else

{

Showform2 ();

}

}

}

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

New Post(0)