Code parsing for midletsuite, MIDlet, schedule, display, and midletstate

Source: Internet
Author: User

The com. Sun. MIDP. Main. Main. Java file is the starting point of MIDP. It contains functions such as main, manage, and runlocalclass. In runlocalclass, midletsuite is created and MIDlet is created:

Midletsuite; </P> <p> try {<br/> // assume a class name of a MIDlet in the classpath <br/> midletsuite = devmidletsuiteimpl. create (internalsecuritytoken, <br/> state. descriptorname, <br/> state. midletclassname, <br/> dev_storage_name, <br/> state. securitydomain); </P> <p> // if no class name was specified than repeat the selector <br/> do {<br/> If (! Scheduler. getscheduler (). schedule (midletsuite) {<br/> // shutdown <br/> break; <br/>}< br/>} while (state. midletclassname = NULL); <br/>} catch (throwable e) {<br/> E. printstacktrace (); <br/>}

Devmidletsuiteimpl is a subclass of midletsuiteimpl, and midletsuiteimpl implements the midletsuite interface;

The schedener class implements the listener and systemeventlistener interfaces. The midleteventlistener interface defines methods startmidlet, pausemidlet, and destroymidlet; The systemeventlistener interface defines methods shutdown. In addition, schedener implements schedule and getscheduler; the getscheduler static method creates a scheduler instance. The schedule method extracts the MIDlet name from the midletsuite and calls the static method of the midletstate class createmidlet to create a MIDlet object;

The midletstate class is used to manage the status of the MIDlet. This is an abstract class and the main abstract methods include:

Protected abstract void Startapp () throws midletstatechangeexception; <br/> protected abstract void pauseapp (); <br/> protected abstract void destroyapp (Boolean unconditional) <br/> throws fail;

The createmidlet method creates a MIDlet based on the input MIDlet Name:

Static MIDlet createmidlet (string classname) throws <br/> classnotfoundexception, instantiationexception, <br/> illegalaccessexception {<br/> class midletclass; <br/> Object MIDlet; </P> <p> synchronized (createmidletlock) {<br/> try {<br/> allowedtocreatemidlet = true; </P> <p> midletclass = Class. forname (classname); <br/> MIDlet = midletclass. newinstance (); <br/> If (MIDlet instanceof MIDlet) {<br/> return (MIDlet) MIDlet; <br/>}</P> <p> throw new instantiationexception ("class not a MIDlet"); <br/>} finally {<br/> allowedtocreatemidlet = false; <br/>}< br/>

In the MIDlet construction, the midletproxy object is created; the midletproxy class is a subclass of the midletstate abstract class; In its static structure, the midletstatemapimpl object is created;

In the construction of the midletstate, a lot of work related to the display Initialization is done:

First, call the static constructor of the display class, Read Device-related information through devicecaps, create a displaymanager instance, and create an event listener that is continuously waiting for wake-up, this is the root cause of MIDP program event-driven;

Static {</P> <p>/* done this way because native access to static fields is hard */<br/> devicecaps c = new devicecaps (); </P> <p> width = C. width; <br/> Height = C. height; <br/> adornedheight = C. adornedheight; <br/> erase_color = C. erasecolor; <br/> display_depth = C. displaydepth; <br/> display_is_color = C. displayiscolor; <br/> pointer_supported = C. pointersupported; <br/> motion_supported = C. motionsupported; <br/> repeat_supported = C. repeatsupported; <br/> is_double_buffered = C. isdoublebuffered; <br/> fg_color = 0; <br/> bg_h_color = fg_color; <br/> fg_h_color = erase_color; </P> <p> text. fg_color = fg_color; <br/> text. fg_h_color = fg_h_color; </P> <p> alpha_levels = C. numalphalevels; </P> <p> keycode_up = C. keycodeup; <br/> keycode_down = C. keycodedown; <br/> keycode_left = C. keycodeleft; <br/> keycode_right = C. keycoderight; <br/> keycode_select = C. keycodeselect; </P> <p> C = NULL; // Let the devicecaps instance be garbage collected </P> <p>/* Let COM. sun. MIDP classes call in to this class. */<br/> displaymanagerimpl = new displaymanagerimpl (); <br/> displaymanagerfactory. setdisplaymanagerimpl (displaymanagerimpl); <br/> deviceaccess = new displaydeviceaccess (); <br/> eventhandler = geteventhandler (); </P> <p> screengraphics = graphics. getgraphics (null); <br/>}< br/>

The construction of the midletstate also creates the display structure through the displaymanager instance created: and creates another private class displayaccess object in the display class; displaymanager is all the display controllers in the MIDP, displayaccess is driven by displaymanager. Both classes come from the displayevent interface, but their division of labor is different;

Protected midletstate (MIDlet m) {<br/> displayaccess accessor; </P> <p> MIDlet = m; <br/> state = paused_resume; // so it will be made active soon <br/> scheduler = scheduler. getscheduler (); <br/> mutex = scheduler. getmutex (); </P> <p> synchronized (createmidletlock) {<br/> If (! Allowedtocreatemidlet) {<br/> midletsuite suite = scheduler. getmidletsuite (); </P> <p> If (suite! = NULL) {<br/> suite. checkifpermissionallowed (permissions. AMS ); <br/>}</P> <p> // force the creation of the display <br/> displaymanager = displaymanagerfactory. getdisplaymanager (); <br/> accessor = displaymanager. createdisplay (classsecuritytoken, MIDlet); <br/> display = accessor. getdisplay (); </P> <p> If (Scheduler. getmidletsuite (). istrusted () {<br/> accessor. settrustedicon (classsecuritytoken, true); <br/>}< br/>

 

 

Finally, we will summarize the classes and their relationships encountered in this section:

MIDlet:

Midletsuite interface; midletsuiteimpl class implements the midletsuite interface;

Midletstate class: implements functions such as Startapp and pauseapp that change the MIDlet state. This is an abstract class; midletproxy is the implementation class of this abstract class;

Midletstatemap interface: midletstatemapimpl: Based on the MIDlet, you can find the status of the MIDlet in the map;

MIDlet class: abstract class; implements methods such as getapppropery and platformrequest;

Schedule class: scheduling class, which determines which MIDlet in the midletsuite is used and changes its status;

 

Display:

Display class: Basic Class Related to the midp ui; displayaccess and displaymanagerimpl are private classes of display; displaymanagerimpl is created in the static structure of display, create the display and displayaccess objects in createdisplay of displaymanagerimpl;

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.