import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.util.Resources;
import java.io.IOException;
import javax.microedition.midlet.*;
public class DemoUI extends MIDlet implements ActionListener{
Label centerLabel;
public void startApp() {
Display.init(this);
Form f = new Form("My LWUIT Demo");
f.setLayout(new BorderLayout());
Image img = null;
Image imgSave = null;
Image imgEdit = null;
Resources r = null;
try {
r = Resources.open("/rahul.res");
// helpCommand = new Command("Help",r.getImage("help_normal"),1);
// helpCommand.setPressedIcon(r.getImage("help_pressed"));
// settingsCommand = new Command("Settings",r.getImage("setting_normal"),2);
// settingsCommand.setPressedIcon(r.getImage("setting_pressed"));
// img = Image.createImage("/img/icon.png");
// imgSave = Image.createImage("/img/icon.png");
// imgEdit = Image.createImage("/img/icon.png");
} catch (IOException ex) {
ex.printStackTrace();
}
centerLabel = new Label("Center Label");
centerLabel.setIcon(img);
f.addComponent(BorderLayout.CENTER, centerLabel);
f.addComponent(BorderLayout.NORTH, new Label("North Label"));
f.addCommand(new Command("Exit",1));
f.addCommand(new Command("Command2",2));
f.addCommand(new Command("Command3",3));
f.addCommand(new Command("Command4",4));
f.addCommand(new Command("Command5",5));
f.addCommand(new Command("Command6",r.getImage("help_normal"),6));
f.addCommand(new Command("Command7",r.getImage("setting_normal"),7));
f.addCommandListener(this);
f.show();
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void actionPerformed(ActionEvent arg0) {
int cmdId = arg0.getCommand().getId();
switch(cmdId){
case 1 : exit(); break;
case 2 : sampleAction(); break;
}
}
private void sampleAction(){
this.centerLabel.setText("Command2 Acknowledged!");
}
private void exit() {
destroyApp(true);
notifyDestroyed();
}
}