October 25, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Introducing a Lightweight UI Toolkit: Bringing Desktop Development into Java ME

  • July 17, 2008
  • By Ibon Urrutia
  • Send Email »
  • More Articles »

But, setting every component's appearance programmatically might be tedious and error-prone, so LWUIT offers an alternative way to declare styles, Themes: Java properties files that specify all style parameters of UI items. You have an example in the following listing.

fgSelectionColor= 0017ff
font= System{ FACE_SYSTEM ; STYLE_PLAIN; SIZE_SMALL }
Form.bgImage=myBackground
Form.font=Bitmap{Serif}
SoftButton.bgColor= ff
SoftButton.fgColor= ffffff

Resources

Other things that beautify any program are images, icons, and fonts. LWUIT has the ability to bundle all resources in a single file, thereby improving compression (separate files always take up more bytes than a bundle of them, one lesson that you learn developing mobile apps). To ease creation and maintenance of resource files, apart from some ant task definitions, LWUIT developers distribute a resource editor application in the LWUIT download (util folder). And, good news for developers, it also could be used to create themes using a graphic interface. You won't have to remember all the keys of a theme file.



Click here for a larger image.

Figure 6: Theme Editor of ResourceEditor

What I miss about these themes is a way to distinguish different classes of the same component. At this moment, if you specify a background color of buttons in a theme, the only way to have a button with a different appearance is by changing its Style programmatically. Components with Style changed programmatically don't obey rules defined with themes unless you call Style setXXX methods with a boolean parameter set to true.

Images

Images are one of the big headaches for JavaME developers: you need them, but they very much increase the size of your jar, and loading too many images into memory could exhaust your phone's capacity fast.



Click here for a larger image.

Figure 7: Image Panel on ResourceEditor

LWUIT introduces the indexed image concept: images that occupy less memory, composed by two arrays, an array of integers (image pixels), and an array of bytes (pixel colors). Following this definition, it is easy to suspect what their caveats are:

  • Your images can have 256 only colors.
  • They are slower to render than normal images because they require a lookup for every pixel.
  • You have to use a resource file to use them because there isn't any standard implemented on devices that allows this kind of images.

I'm not going to use them in this project, but they may be very useful in an application with intensive use of graphics; for example, for defining background images on buttons, although using tiled images is even cheaper in terms of memory usage.

Another noteworthy point about the Image class is the inclusion of scaling methods on it; its lcdui counterpart lack of them. Although you lose some resolution on scaled images, they alleviate the need of adding a new bigger (or smaller) version of the file on the jar.

Fonts

With LWUIT, you can substitute a phone's implemented fonts, that often look awful, with nice, antialiased fonts. You can select any font installed on your computer, and create an archive inside the resources file that packages it to use in any component. You also can define what is going to be used in the charset; and in your case, don't forget to add a º (degree symbol) to mark angles and temperatures.



Click here for a larger image.

Figure 8: Font maker


Tags: mobility



Page 5 of 7



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel