J2ME learning Notes (5 )—– MIDlets in GUI (graphical) Programming

  Abstract: The study notes J2ME (5 )—– MIDlets in the GUI (graphical) Programming 

  MIDlets in the GUI (graphical) Programming <? Xml: namespace prefix = o ns = "urn: schemas-microsoft-com: office: office" /> 

  1.    Summary 

  MIDP MIDP running in the container MIDP defines an API application, the API itself is built on the CLDC API.    MIDP API user interface design of the Java class is not based on Java Abstract Window Toolkit (AWT) category, but for mobile phones such small mobile information equipment specially designed.    Such equipment only limited screen size and keyboard performance.    When programmers use MIDP prepared graphics application, or they can only use the MIDP CLDC API. 

  2.    MIDP GUI category 

  1) All categories are javax.microedition.lcdui MIDP GUI component of the package. 

  2) the basic MIDP abstract user interface is graphical screen, Screen category of equipment for the graphics and user interaction to the package.    Each application can display a screen. 

  3) MIDP API with "senior (high-level)" and "low-level (low-level)," UI category. 

  Senior UI —– such as Form, List, TextBox, TextField, Alert Ticker with equipment and functional adaptation, its images, text, text, and other jurisdictions, as well as radio button to support. 

  UI junior category —– such as Canvas allows the operator arbitrary painting. 

  3.    MIDP GUI in the major categories 

  1) Graphics category —– provided for 2-D geometric objects painting of the Graphics object. 

  Javax.microedition.lcdui.Graphics category is not explicit in MIDlet created that the abstract images in the category Canvas MIDP GUI programming provided paint () method, piant () method from a type Graphics parameters, use this MIDlet parameters in the Graphics class to achieve the function. 

  2) Displayable category —- is an abstract class, Displayable object processing MIDlet the GUI output It has two javax.microedition.lcdui.Canvas and javax.microedition.lcdui.Screen derived class. 

  3) Canvas class —– Canvas class allows the operator arbitrary painting, and the Graphics class are low-level UI. Provided by the Graphics class of the method of the Canvas class always used in the derived class. 

  4) Screen category —– senior UI, Form, List, TextBox, Alert category are a derivative of it. 

  4.    Below is a section of the Graphics class usage of the code: 

  Import javax.microedition.midlet .*; 

  Import javax.microedition.lcdui .*; 

  Public class MidpGraphics extends MIDlet implements CommandListener 

  ( 

  Display display; 

  TestCanvas canvas; 

  Public MidpGraphics () 

  ( 

  Display = Display.getDisplay (this); 

  Canvas = new testCanvas (); 

  ) 

  Public void startApp () throws MIDletStateChangeException 

  ( 

  Display.setCurrent (canvas); 

  ) 

  Public void pauseApp () 

  ( 

  ) 

  Public void destroyApp (boolean unconditional) throws MIDletStateChangeException 

  ( 

  ) 

  Public void commandAction (Command c, Displayable d) 

  ( 

  ) 

  ) 

  Class testCanvas extends Canvas 

  ( 

  Public void paint (Graphics g) 

  ( 

  / / Create font objects 

  Font font = Font.getFont 

  (Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM); 

  / / Font set targets 

  G.setFont (font); 

  / / Figured out the text 

  G.drawString ( "Hello MIDP," getWidth () / 2, getHeight () / 2, Graphics.HCENTER | Graphics.TOP); 

  Try 

  ( 

  / / Figured out the image 

  Image image = Image.createImage ( "myimage.png"); 

  G.drawImage (image, 0,0, Graphics.HCENTER | Graphics.TOP); 

  ) 

  Catch (Exception e) 

  ( 

  ) 

  ) 

  ) 

  —————————- Running effect on the screen is the center of the text "Hello MIDP." 

  5. MIDlet programming with SaveMyMoney banking application to achieve the different graphical user interface code examples: 

  1) Mission statement: The first display contains called Balance Enquiry (current balance), Fixed Deposit Enquiry (regular savings), Check Status Enquiry (check status) of the menu 

  When users choose Balance Enquiry should show progress indicator 

  When users choose Fixed Deposit Enquiry should show progress indicator 

  When users choose Check Status Enquiry into the cheque, should show the TextBox 

  When users enter, after the cheque should show progress indicator 

  2.    Code as follows: 

  / / Import and Midlet packet lcdui 

  Import javax.microedition.lcdui .*; 

  Import javax.microedition.midlet .*; 

  / / MidpGui expansion of the definition of MIDlet 

  Public class MidpGui extends MIDlet implements CommandListener 

  ( 

  / / Display category created by the display managers 

  Display display; 

  / / Definition of the form object 

  Form form = new Form ( "Container Form"); 

  / / Screen derived class 

  / / Definition of the list (Main Menu) 

  List menu; 

  / / Definition of text box 

  TextBox input; 

  / / Item category of components (Gauge category that showed a bar graph on the screen) 

  Gauge gauge = new Gauge ( "Your enquiry is being processed," false, 100, 30); 

  / / Definition of the order from the Command 

  Static final Command okCommand = new Command ( "OK", Command.OK, 1); 

  Static final Command backCommand = new Command ( "Back" Command.BACK, 0); 

  Static final Command exitCommand = new Command ( "Exit", Command.STOP, 2); 

  String currentMenu; / / definition of string variables to the current form of identification 

  Public MidpGui () 

  ( 

  ) 

  / ** 

  * The startApp () starts the MIDlet, creates a list of items and 

  * Uses the EXIT command * / 

  Public void startApp () throws MIDletStateChangeException 

  ( 

  / / Object by display 

  Display = Display.getDisplay (this); 

  / / Create the initial menu and add items 

  Menu = new List ( "Enquiries" Choice.IMPLICIT); 

  Menu.append ( "Current Balance", null); 

  Menu.append ( "Fixed Deposit", null); 

  Menu.append ( "Check Status", null); 

  / / Accession to the order form Exit 

  Menu.addCommand (exitCommand); 

  Menu.setCommandListener (this); 

  / / Call mainmenu, set up the initial screen 

  MainMenu (); 

  / / Components to the form by adding measures 

  Form.append (gauge); 

  ) 

  / / Method mainMenu 

  Void mainMenu () 

  ( 

  Display.setCurrent (menu); 

  CurrentMenu = "Main"; 

  ) 

  Public void pauseApp () ( 

  Form = null; 

  Display = null; 

  Menu = null; 

  Input = null; 

  Gauge = null; 

  ) 

  / / When the call was withdrawn MIDlet 

  Public void destroyApp (boolean unconditional) throws MIDletStateChangeException 

  ( 

  NotifyDestroyed (); 

  ) 

  / / Display TextBox component 

  Public void showTextBox () 

  ( 

  Input = new TextBox ( "Enter the Check Number:", "", 20, TextField.ANY); 

  Input.addCommand (backCommand); 

  Input.addCommand (okCommand); 

  Input.setCommandListener (this); 

  Input.setString (""); 

  Display.setCurrent (input); 

  CurrentMenu = "input"; 

  ) 

  / / Display screen progress indicator 

  Public void showForm () 

  ( 

  Form.addCommand (backCommand); 

  Form.setCommandListener (this); 

  Display.setCurrent (form); 

  CurrentMenu = "form"; 

  ) 

  / / Activation orders 

  Public void commandAction (Command c, Displayable d) 

  ( 

  String label = c.getLabel (); 

  If (label.equals ( "Exit")) 

  ( 

  Try ( 

  DestroyApp (true);) 

  Catch (Exception e) () 

  ) 

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

  ( 

  If (currentMenu.equals ( "input") | | currentMenu.equals ( "form")) 

  ( 

  / / Go back to menu 

  MainMenu (); 

  ) 

  ) 

  Else 

  ( 

  If (label.equals ( "OK")) 

  ( 

  ShowForm (); 

  ) 

  Else 

  ( 

  List down = (List) display.getCurrent (); 

  Switch (down.getSelectedIndex ()) 

  ( 

  Case 0: showForm (); break; 

  Case 1: showForm (); break; 

  Case 2: showTextBox (); break; 

  ) 

  ) 

  ) 

  ) 

  ) 

  Note: All category and an explanation of the methodology can view J2ME doc. Path for the x: \ WTK104 \ docs \ api 

  ↑ Back 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Recommend Articles

Comments

Leave a Reply