Nov 20, 2013

Networking ME v1.1: URLLabel and URLButton for LWUIT

Hi, all

Continuing our two-parts introduction post about the news in Networking ME v1.1.

In the first post, we introduced the new content listeners. Now in this second one, we will show you three LWUIT components built on top of the library: ImageListener, URLLabel and URLButton.

ImageListener class is a content listener for LWUIT Image. Such as the class name, It works same as the ImageListener class for LCDUI Image. (This component could have been introduced in the fist post, but I decided to talk about it here, since this post is focused on LWUIT)

...
URL url = new URL("http://www.emobtech.com/images/pic.png");
HttpRequest req = new HttpRequest(url);
//
RequestOperation oper = new RequestOperation(req);
oper.start(new ImageListener() {
    public void onImage(Image image) {
        Label imgLabel = new Label(image);
        //        
        form.addComponent(imageLabel);
    }
...
});
...

This code snippet downloads an image from an URL. The image's bytes are converted to a LWUIT Image object and then it is added to the form to be displayed. Easy, huh? So, keep reading, you will be introduced to a easier way to accomplish the same result.

...
URL url = new URL("http://www.emobtech.com/images/pic.png");
URLLabel imageLabel = new URLLabel(url);
//
form.addComponent(imageLabel);
...

How about this? A lot easier, right? URLLabel class receives an URL as parameter in a constructor and downloads the image automaticaly. Once download is down, the image is displayed. It reminds me the ease of displaying images in HTML pages, by just informing the image's URL in the "img" tag's "src" attribute.

Besides the URL, URLLabel has an optional parameter that works as a placeholder, displayed while the image is downloaded. This placeholder can be either a String or Image object.

Last but not least, URLButton class has the same features as URLLabel. Use this one in case the image you want to display is touchable.

...
URL url = new URL("http://www.emobtech.com/images/pic.png");
URLButton imageButton = new URLButton(url);
//
form.addComponent(imageButton);
...

This finishes our our two-parts introduction post about the news in Networking ME v1.1. I reinforce the invitation to visit the project's website and download the release v1.1.0.

Hopefully everybody has enjoyed the news.

See you in the next post...

1 comment:

Unknown said...

Very nice post here thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
seo company in chennai