J2ME Polish learning experience (1) ---- Device Optimization

xiaoxiao2021-03-05  24

Recently, I have learned J2ME, but I don't have many headaches, such as different hardware features of different devices, JAR and JAD automatic packaging, DEBUG difficult, and so on. But later I found this project for J2ME PLISH, I found that all J2ME programmed a dreamer, so introduced to everyone.

J2ME Polish is an open source project for the Germans, and the homepage is:

Http://www.j2mepolish.org/, similar to a Java development environment plug-in. The first one introduces its device optimization function (Device Optimization).

For example, this often encountered, your MIDLET needs to make some sounds, you know that the MMAPI or MIDP 2.0 devices can be used as follows:

InputStream IS = getClass (). GetResourceAsStream ("/ mymid.mid");

Player Player = Manager.createPlayer (IS, "Audio / MIDI");

Player.Realize ();

Player.start ();

But there are still many mobile phones in MDIP1.0, many mobile phones have their own API, such as in the Nokia UI, so that you can:

Sound a = New Sound (400, 1000);

A.SETGAIN (100);

A.Play (1);

If you can use your program on these two mobile phones, what should I do? Do you safeguard two source code? This will be very troublesome. So, I think if there is a compilation preprocessing similar to C in Java, so that you can come:

#IF device supports MMAPI or MIDP2.0

// Do Something Here

#ELIF equipment supports Nokia UI

// Do Something Diference Here

#ENDIF

The compiler then automatically generates a Class file for different devices. This solution can be perfect, while J2ME Polish can help you do this, J2ME Polish gives Java with pretreatment function, the code is as follows:

// # i polish.midp2 || polish.api.mmapi

Try {

InputStream IS = getClass (). GetResourceAsStream ("/ mymid.mid");

Player Player = Manager.createPlayer (IS, "Audio / MIDI");

Player.Realize ();

Player.start ();

} catch (MediaException me) {

// # debug error

System.out.println ("Unable to Play MIDI" ME);

} catch (ioexception ie) {

// # debug error

System.out.Println ("Unable to Load Midi" IE;

}

// # Elif Polish.Api.Nokia-UI

Sound a = New Sound (400, 1000);

A.SETGAIN (100);

A.Play (1);

/ / # ENDIF

I want the code above, I don't have to explain, can you understand? // # IF is the preprocessing flag identified by J2ME Polish. In addition to "//", it is identical to the syntax in C , which is identical (// debug, the DEBUG function provided by J2ME Polish, is also very powerful, later explained later). Polish.midp is a predefined symbols and variables. J2ME Polish defines a considerable number of symbols and variables that you can write different code according to different platforms, APIs, sounds, and image processing capabilities. How is the target file generated? J2ME Polish uses Ant as a compilation management tool, in build.xml, there is such a section:

How, the grammar is very straightforward, meaning that you want your program to generate the result of the two platforms, which is the Nokia S40 and a general support for MIDP2. J2ME Polish comes with a database, device.xml, contains various types of phones type feature information, so when compiling, the previous type of hardware will automatically use the NOKIA UI code, and the latter code will select the MIDP2 code. How, isn't it very easy? There are still a lot of good features, continue next time.

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

New Post(0)