import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class HelloMicroWorld extends MIDlet {
private Display display;
private TextCanvas canvas;
public HelloMicroWorld() {
display=Display.getDisplay(this);
canvas=new TextCanvas(this);
}
public void startApp() {
display.setCurrent(canvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void exitMIDlet() {
destroyApp(true);
notifyDestroyed();
}
}
class TextCanvas extends Canvas implements CommandListener {
private Command cmExit;
private String text;
private HelloMicroWorld midlet;
public TextCanvas(HelloMicroWorld midlet) {
this.midlet=midlet;
text="Hello Micro-World!";
cmExit=new Command("Exit",Command.EXIT, 1);
addCommand(cmExit);
setCommandListener(this);
}
protected void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(0,0,getWidth(),getHeight());
g.setColor(0,0,0);
g.drawString(text,getWidth()/2,getHeight()/2,Graphics.BASELINE|Graphics.HCENTER);
}
public void commandAction(Command c, Displayable d) {
if (c==cmExit)
midlet.exitMIDlet();
}
}