Sunday, January 15, 2012

J2ME with LWUIT (Initializing)

LWUIT is a SWING like lightweight widget library for J2ME. It is very useful for software development with J2ME. I could find a very useful guide for LWUIT. It is available here.

LWUIT class hierarchy is useful when we use LWUIT wifgets.

First LWUIT program

package hello;

import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.layouts.BorderLayout;
import javax.microedition.midlet.*;

 * @author Kanishka
public class DemoUI extends MIDlet {

    public void startApp() {
        Form f = new Form("My LWUIT Demo");
        f.setLayout(new BorderLayout());

        Image img;
        try {
            img = Image.createImage("/img/img.png");

            Label centerLabel = new Label("Center Label");
            f.addComponent(BorderLayout.CENTER, centerLabel);
            f.addComponent(BorderLayout.NORTH, new Label("North Label"));
        } catch (IOException ex) {

    public void pauseApp() {

    public void destroyApp(boolean unconditional) {

Note : First of all. We have to init the display. in line 17 . I have initialized the display by calling Display.init() method. This must be done inside start() method. not inside the constructor.


© kani.stack.notez 2012 | Blogger Template by Enny Law - Ngetik Dot Com - Nulis