Let’s try J2ME Polish!

Suppose you’ve developed a game that starts with a menu of options using the standard MIDP lcdui menu components. It won’t be long before you notice that — on practically every MIDP handset — the lcdui menu components are, well, kind of ugly. And since the lcdui package has a “simplicity over flexibility” philosophy, there’s not a lot you can do to improve your game’s appearance without dumping the lcdui components entirely and drawing your own menu widgets onto a canvas. That’s a lot of work for an existing game, and a possible alternative strategy is to go with J2ME Polish.

J2ME Polish is a set of user-interface libraries that you can add to a MIDlet jar, plus the tools to automatically transform an existing lcdui interface into one that uses the polished user-interface libraries (for a price, of course…).

J2ME Polish works by sending your code through a pre-processing phase that transforms the lcdui calls so that they call J2ME Polish classes instead. To indicate which parts of the code you’d like to transform and how, you add pre-processing directives to your code (very much like the pre-processing directives used when programming in C). To define the precise look-and-feel you want (for example the colors and images to use), you write a series of cascading style sheets and create a hierarchy of resource directories for the various devices you’d like to support and/or for the various “skins” you’d like to use. All the bits of the build process are controlled by standard Ant build scripts.
Sound complicated?

Actually it is, but it’s a lot simpler than attempting to write your own custom user interface from scratch. Unfortunately most of the complexity comes from compensating for all of the differences from one handset to the next, and — with or without J2ME Polish — you always have to deal with this problem if you want to have graphics that look good on a wide range of handsets.

In practice J2ME Polish is pretty easy to use. I know this because I’ve used it professionally — here’s a game catalog skin we did for Orange using J2ME Polish:

ege_catalog.jpg

I liked working with J2ME Polish because the natural complexity of the custom user interface problem is organized in a logical way, plus the online documentation is quite clear and extensive, and it’s nice that it follows standards such as css and Ant. (If you’re not already using Ant to build Java ME projects, you probably should be 😉 )

For my latest programming exercise, I decided to download J2ME Polish and see how hard it would be to customize the demo to run on my Sagem my700x. As you can see from the above photo, I’ve already done a J2ME Polish project for this very handset, but I can’t just post the EGE code here because that would be too easy (not to mention illegal…). Anyway, it’s more interesting to start from scratch.

Downloading and installing it was no problem, so I headed straight for the tutorial. The tutorial consists of building a simple sample menu midlet that illustrates how to add some basic J2ME Polish preprocessing directives to transform an lcdui menu into a polished menu. Plus a basic build script and resource directories. To build the sample, all I had to do was go into the menu directory (the directory containing the correct build.xml file) and type “ant.” (If I hadn’t had Ant already set up and configured on my machine, there would of course be an extra step here…) Ant proceeded to build a series of jad and jar files for both the English and German versions of the sample for the following handsets: Sony-Ericsson/P900, Nokia/Series60, Nokia/Series60Midp2, Generic/midp2, Generic/midp1. Naturally, my first thought was to poke around in the build.xml file to see where this list of handsets is defined so I could add my Sagem to it. It was pretty easy to find (in the “deviceRequirements” element), so — following the pattern — I added “Sagem/my700x”.

Just adding the Sagem my700x to the build file wasn’t sufficient though, since — as you might guess — the capabilities of the devices are defined in a file somewhere, and my handset wasn’t there. Grepping around for terms like “Nokia” and “Sagem” I found the capabilities of each device defined in “devices.xml” and “custom-devices.xml.” The “devices.xml” file listed a Sagem myX7, but the capabilities weren’t quite the same as my handset (notably the screen size and CLDC version were off), so I added a new entry for my handset, following the model of the others.

The “custom-devices.xml” file says in its header that you’re supposed to modify that file instead of modifying “devices.xml,” but for some reason just adding the device to “custom-devices.xml” didn’t work. I could read the manual to try to figure out why (because you know how they say “when all else fails read the manual”), but all else hadn’t failed yet since adding it to “devices.xml” worked. 😉 And anyway, for this exercise I just wanted to see how quickly I could get the project working — beautification comes later.

To find the data to use in the “devices.xml” file, I consulted the J2ME Polish device database. This is a great resource because it lists all sorts of useful data for developers about a huge list of handsets. In particular, it lists a lot of the softkey keycodes which (as I mentioned earlier) are often hard to find. It didn’t list the keycodes for my little Sagem, but fortunately I’d figured them out myself in my previous exercise about keycodes.

The reason I want to know the keycodes for the softkeys is because that allows J2ME Polish to polish the softbar — that is, to draw a pretty softbar that matches the rest of the user-interface design rather than having a mixed look that includes polished user-interface components with an ugly lcdui softbar.

Obviously I wanted the nice polished softbar since I have the data to do it, so in the “devices.xml” file I added the “LeftSoftKey” and “RightSoftKey” data to my description of my Sagem my700x, following the example of some other handset descriptions that had softkeys listed. That wasn’t sufficient to get it to use the softkey values and create a pretty softbar though, so this time I finally broke down and consulted the documentation to figure out why. Annoyingly enough, I couldn’t find anything about softkeys except a hint that in the build element of the build.xml file the “fullscreen” attribute needs to be set to “true” or “menu.” It was already set to that, though, so I figured there had to be something else. So, back to the standard troubleshooting bag of tricks, I compared the device descriptions of those devices with polished softbars and those without, and a little trial and error led to the idea that “hasCommandKeyEvents” needs to be listed in the “features” element of the device. That did the trick, and I ended up with a nice little demo for my handset.
All in all, I would say it was about a half-day’s worth of work (including some leisurely coffee-breaks 😉 ).

For a professional project, I would of course recommend reading the manual or the book first in order to set everything up right (rather than just sloppily plunging forward as I’ve done here), but as you can see from this example, J2ME Polish is a pretty quick and easy way to fix up your MIDlet’s user interface.

Advertisements

26 comments so far

  1. mika li on

    Hi Carol,

    Congrats on your new book launch. I have been following your blog and find your posting very enlightening.

    Concerning this post on J2ME Polish, I’d like to welcome you to have a look at TWUIK, a J2ME UI technology for creating advanced UI for your midlets, much like what “Adobe FLASH” is capable of on your desktop.

    Feel free to browse the many examples of TWUIK-based midlets via my videos at http://www.tricastmedia.com/videos

  2. carolhamer on

    Thanks, that looks very interesting. Is it possible to get an individual (trial) license?

  3. Amri Shodiq on

    It is really inspiring to read your article. But, really, I tried to install J2ME Polish and integrated it with my Netbeans 6 Beta version. The result is, after I start my Netbeans and try to make J2ME Polish project, there is no J2ME Polish option in the project menu.

    I use windows vista. Do you have any suggestion for me about how to use (or maybe install) J2ME Polish correctly?

    Please send me an email. I need this so much for my work.

  4. carolhamer on

    I’d like to help, but I haven’t really used Netbeans…

  5. Amri Shodiq on

    It’s finally work. Just impatience.

  6. Hojjat on

    please tell me what I need to work with j2me polish
    I mean the list of requirment and how to download them.
    Tnx

  7. carolhamer on

    Hi Hojjat, For details, see the J2ME Polish site.

  8. DR on

    Hi Carol,
    Did you have a look at the license of TWUIK. I mean did you contact them regarding it ?

    Regards,
    DR

  9. carolhamer on

    No. I looked over their website, and it wasn’t clear how to do it, then I got sidetracked on other projects. If someone has some more info, though, I’d be curious about it. I’ll probably look into it further in order to mention it in my Jazoon talk.

  10. gabi on

    i saw that you talk about TWUIT and I’m also interested. can you live me a link to their web site? thanks

  11. prayag on

    Hi ,I am new in j2me polish.Please give some example code from where I can start programming in j2me polish.I have tired from http://www.j2mepolish.org but can’t success.

  12. Jim - 406NotAcceptable on

    I’ve noticed there are a number of issues with J2ME Polishes’ current Netbeans plug-in (or it’s a Netbeans problem!) For a couple of fixes for J2ME Polish look here.

    http://www.406notacceptable.com/j2me/fixing-j2me-polish-integration-with-netbeans-6/

    I really find the Java 1.5 support to be the best feature of polish; whilst many places put focus on the GUI tools, their strength will take a hit when SVG support on devices improves to the point where developers can use Netbean’s SVG menu designer.

  13. Umme Essa on

    Hi,

    Nice post. I am new to j2me polish. I am writing a browser with basic tags support. Like I have to support form, table, hr, images and links. I have written most of the things. I have got stuck in two things 1) When I put interactive items in a tableitem they are not focusable and editable. I have tried selection mode but it doesn’t work. Do you have any idea how this can be fixed?

    2) I have to support cookies, according to their documentation we can write our own custome protocol handler. I think I can write the protocol handler and set cookie with every request. What do you think am I right?

    Thanks
    Umme Essa

  14. Harpish - mp3 downloading on

    Hi Carol,

    Is there an alternative to j2me polish, prefabily a free one?

    Regards,

    H

  15. akash on

    Hey guys,

    I have installed J2ME polish and integrated it with eclipse. I am trying to create new project with Polish.
    After selecting the J2ME polish path and selecting devices, when I click on next, it does not go further.

    Could you please help me on this?

    Regards
    Akash

  16. […] works as you’re using it — J2ME Polish is a good place to start, as I explained here.  But in practice, I found that I wanted 100% control over the look-and-feel of the GUI, which I […]

  17. j2me beginner on

    I read about j2me polish , i tried to install to my MyEclipse IDE but i am not able to install it. What shall i do, whenever i install i get an error of installing a plugin name org.eclipse.jface.databinding(1.2.0). I tried to find this plugin on net but i could not find it. Tell me how to use it. I have created a simple application using MIDLET and SERVLET, i am able to fetch the data for the database and show it on the mobile screen (using wtk). Now i want to display it more professionally so i wanted to use the j2me polish but i am not able to know how to use it. Do mail me, i need some suggestion as soon as possible.

  18. carolhamer on

    I’ve gotten a couple of questions about using J2ME Polish with Eclipse, and I’d like to help, but I don’t use Eclipse.

    I’ve used Eclipse in a few professional projects (so I know it can do some cool things), but each time I found that it was ultimately simpler just to build my project from the command line using Ant. I like the fact that with Ant I can see all of the build configuration and all of the calls (with their options) in a straight-forward, readable format. The Eclipse people can debate me on this, but I’ve found that for troubleshooting problems, it’s easier to have all of this information visible than to go through Eclipse, which stores the project parameters in a project file whose contents are kind of obscure.

  19. Darrick on

    Hey , I found your article very interesting, I am starting working with J2ME polish, I already have an application up and run but I have to modify it a little bit. The way I want to do it is via the use of polish.css file i try to modify it and then compile, build the project and launch a jar file onto an MIDP 2.0 emulator, the problem is that The styles I am trying to define in polish.css file are not recongnised or simp overwritten, have you got any clue whas wrong or where I can find some relevant informatmion to sort this problem out, thanks in advance

  20. carolhamer on

    Hi Darrick,

    If you’re having trouble with changes in the polish.css file getting ignored or overwritten, I would suspect that it’s a problem in your resource file tree.

    The root folders are more general categories, and subfolders are more specific. For example, the folder “resources/Nokia/N95” would contain the resources for building the polished skin for the Nokia N95. The most specific resources available for each device will be used, so if you have a polish.css file in the folder “resources/Nokia/N95” and another polish.css in the “resources” folder, then the one in the “resources/Nokia/N95” folder is the one that will be used when building the jar for the Nokia N95.

    (See also the J2ME polish docs on resource assembly.)

  21. Nikhil Shravane on

    Hi Carol, First of all thanks for your wonderful article, reading which I can at least dare to start with Polish. I have already developed midlet in pure Java ME API provided by Sun. As you mentioned, it has very ugly GUI. I tried to make it more attractive, but I have limitations imposed by lcdui, and I don’t want to do custom GUI using Canvas/CutomItem and all those time consuming hardcore programming. Secondly, I want my midlet to be CROSS-PLATFORM to target wide range of devices, so I don’t want to use vendor specific Java API’s. So for me “J2ME Polish” is good option. Am I right? So please guide me how can I transform mu ugly lcdui midlet to Polished midlet? Before that, Please give me some links or screen shots of Polished midlets, so that I can have an idea what can be achieved using Polish, Whether Polish is capable of producing GUI which I want to show e.g.
    1. In the ImageItem Image Label should be LAYOUT_LEFT and Image itself should be LAYOUT_RIGHT.
    2. Can I add color to the Form’s title bar?
    3. Can I show border to the Text Fields?
    4. Can I use different font size on a single form? etc.

    Any help would be greatly appreciated. Thanks and Regards.

  22. sanjeewa on

    j2me polish doesn’t work in 6.8 more errors found pls send me smole tutorial in netbean project

    • Nikhil Shravane on

      Hi Sanjeewa, I am also facing the problems with NetBeans 6.8 after integrating it with Polish. I have opened the project which is given in the Samples. When build the project, it gives the compile time errors.

  23. Blog post about J2ME Polish on

    […] post about J2ME Polish Here's an interesting blog post by someone who gave J2ME Polish a try: Let’s try J2ME Polish! Reply With Quote   + Reply to Thread « Previous Thread […]

  24. Harish on

    i want to use keyevent in j2me polish, how to use ?

  25. circle k furniture on

    It is after all crucial that you must avail the services of a firm which is authentic and it is quite imperative to gauge if they are reliable as well, as this is important for building a trustworthy relationship with them.These are the essential questions which you must ask before availing web development services of a particular firm. vb.net


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: