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 java.io.IOException;
import javax.microedition.midlet.*;
/**
* @author Kanishka
*/
public class DemoUI extends MIDlet {
public void startApp() {
Display.init(this);
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");
centerLabel.setIcon(img);
f.addComponent(BorderLayout.CENTER, centerLabel);
f.addComponent(BorderLayout.NORTH, new Label("North Label"));
f.show();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
}
Result
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.


0 comments:
Post a Comment