Tuesday, March 29, 2011

A New Way To LWUIT

LWUIT had a MIDP bias. It started as a MIDP project so it is perfectly understandable, however moving forward to support RIM and other platforms (e.g. Thorsten's great work) we wanted to completely disconnect LWUIT from its platform specific roots and offer some great new features in the process.
It started off when we generated projects for the GUI builder, but we decided to take this further into the LWUIT Demo and make that approach into our project structure recommendation. You can checkout the source code for the new LWUIT Demo from SVN to see the actual structure.

Basically what we are doing is placing all the LWUIT portable code into a MIDP shared library, this is effectively the common code for the project. Here we also place the common resources used within all the different ports.
Underneath this project (mostly for convenience not due to necessity) we place subprojects that depend on that parent project and are platform specific. That way we don't need a pre-processor or any similar tool to gain both portability and the ability to utilize platform specific features when we want to do so.

The really cool feature hidden beneath this is the ability to utilize the JavaSE port to run the application. Besides running practically instantly (no simulator!), the biggest hit is the ability to use Java SE level development tools!
Edit & continue, profilers, threadalizers, memory monitors etc. Its a whole different scale of debugging for business logic (assuming the issue reproduces on the SE port). Besides debugging this feature allows you to embed your application as an Applet right into a web page to provide users with a live preview of your application! How cool is that!

To your right you can (hopefully) see a running Applet containing the current version of the LWUIT demo. You can use escape as a back button, F1 as the menu button and the arrow keys/mouse to navigate within this Applet.


  1. great work sir!
    Is that mean that I will be able to use LWUIT library in my android project?

  2. Thanks for this post it trully clarified things about the genrated netbeans projecys from the Resource Editor and I was wondering why I ha 3 projects.

    I have thought a problem:When I try to run a simple hello world MIDLEt I receive the following error

    at java.lang.RuntimeException: You must include the platform port before the LWUIT in the classpath

    I'm using Netbeans 6.9.1 and I received this error both with S60 emulator and JAvaMESDK 3.0 emulator.

    Any ideas? Again great job and great programm.

  3. Shai.. by now you got me really hooked into your blog entries.. I just bump into LWUIT a few weeks ago, while looking a way to refresh the UI of an already aging app..

    At first I was thinking of it like a suitable JME Polish replacement.. but now with the ongoing work an announced change of direction.. it looks more an more promising to me.

    I beg you take the time to write a detailed HOWTO on porting an existing LWUIT+JME app to LWUIT+Android for those of us newcomers to the LWUIT, Android arena.

    Thanks again to the LWUIT for all the great work and enthusiasm put into making programmer friendly UI development.

  4. @Martin: Thorsten is working on the Android port.

    @tdgs: if you import the MIDP ui from the ports and not the UI project then make sure you are using the latest version including my fixes to the build.xml files.
    If you are using a project generated by the resource editor I suggest you regenerate a new project with netbeans and copy the jar's to the original project you generated (since the libraries were updated with this fix).

    @Omar: thanks. We usually found that porting JavaME UI code is too much of a pain so we advocate rewriting the UI to take advantage of the things that LWUIT can accomplish. Generally we don't do much porting from MIDP UI so we don't run into this issue often enough to bother us.