J2ME Learning Notes (IV) ----- Developed with specific MIDP API MIDlets Huanghui22 [Original]

zhaozj2021-02-16  105

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

1. Specific classes and interfaces in MIDP 1) javax.microedition.midlet ---- is the innermost package, only one MIDET class, which provides basic feature spending for MIDP applications 2) javax.microedition.io- --- Include the 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 GUI components, Java.aw That is more suitable to use the small screen handheld device in the javax.microedition.lcdui package. 4) javax.microedition.rms (record management system) ----- Support database system different classes And interface, they subsequently store and retrieve data used by MIDlet

2. An example: 1) Task Statement ----- SaveMymoney Bank Mobile Application System First Screen Display Welcome Message, the current date, current time, total memory, and free memory 2) The implementation code is as follows: import javax.microedition.midlet. *; Import javax.microedition.lcdui. *; Import java.util. *;

public class MB extends MIDlet implements 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.da_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 "; break; case 3: month =" april "; Break Case 4: Month = "May"; Break; Case 5: Month = "Jun e "; 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"; Break;}

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; 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; form1.addcommand (Okco); Form1.AddCommand mmand); form1.setCommandListener (this); display.setCurrent (form1);} public void showForm2 () {form2.addCommand (exitCommand); form2.addCommand (backCommand); form2.setCommandListener (this); display.setCurrent (form2 );} Public void command (Command C, Displayable D) {string label = c.getlabel (); if (Label.Equals ("exit")) {destroyApp (true);} else if (Label.equals " "

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

New Post(0)