~cpp
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
class HelloWorldCanvas extends Canvas {
public void paint(Graphics g) {
g.setColor(255,255,255);
g.fillRect(g.getClipX(),g.getClipY(),g.getClipWidth(),g.getClipHeight());
g.setColor(0,0,0);
g.drawString("Hello World!", 0, 0, Graphics.TOP|Graphics.LEFT);
}
};
public class HelloWorld extends MIDlet implements CommandListener {
private Display display;
private HelloWorldCanvas canvas;
private Command exitCommand;
public HelloWorld() {
display = Display.getDisplay(this);
canvas = new HelloWorldCanvas();
exitCommand = new Command("Exit", Command.EXIT, 1);
canvas.addCommand(exitCommand);
canvas.setCommandListener(this);
}
public void startApp() {
display.setCurrent(canvas);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
display = null;
canvas = null;
exitCommand = null;
}
public void commandAction(Command c, Displayable d) {
if(c == exitCommand) {
destroyApp(true);
notifyDestroyed();
}
}
};