J2ME learning Notes (4 )—– with specific MIDP API development MIDlets

  MIDP API with specific development MIDlets 

  1.    MIDP the specific type and interface 

  1) javax.microedition.midlet—– is the most inner bag contains only a MIDlet class, it provides the basic MIDP applications function expenditure 

  2) javax.microedition.io—– including HTTPConnection interface, through this interface, MIDlet equipment can visit the Web data 

  3) javax.microedition.lcdui (Liquid Crystal Display User Interface LCD )—– the GUI user interface components provide support, and java.awt same function, javax.microedition.lcdui included in the category and then I more applicable and small screen devices. 

  4) javax.microedition.rms ()—– records management system to support different types of database systems and interfaces, their subsequent storage and retrieval of the data used in MIDlet 

  2. An example: 

  1) mission statement —– SaveMyMoney mobile banking application systems display a welcome news, and the second on the screen should display the current date, current time, the overall memory, as well as free memory 

  2) The realization of the code below: 

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

  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"; break; 

  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"; break; 

  ) 

  StringItem strItem = new StringItem ( "Welcome to SaveMyMoney 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 (); 

  If (label.equals ( "Exit")) 

  ( 

  DestroyApp (true); 

  ) 

  Else if (label.equals ( "Back")) 

  ( 

  / / Go back to Form1 

  ShowForm1 (); 

  ) 

  Else 

  ( 

  ShowForm2 (); 

  ) 

  ) 

  ) 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags: ,

Releated Articles


0 Comments to “J2ME learning Notes (4 )—– with specific MIDP API development MIDlets”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.