配置好Eclipse + KTW2.2環境後.實現在手機模擬器上顯示HelloWorld字樣
import Javax.microedition.midlet.*;
import Javax.microedition.lcdui.*;
//畫布類,它實現了顯示手機屏幕的內容
class HelloCanvas extends Canvas
{
public HelloCanvas()
{
}
public void paint(Graphics g)
{
g.setColor(255, 255, 255);
g.fillRect(0, 0, getWidth(), getHeight());
g.setColor(0, 0, 0);
g.drawLine(10,10,50,50);
g.drawString("Hello World!", 0, 0, Graphics.LEFT | Graphics.TOP);
}
}
//MIDlet程序入口,顯示畫布
public class HelloWorld extends MIDlet implements CommandListener
{
private HelloCanvas canvas_;
private Display display_;
public HelloWorld()
{
canvas_ = new HelloCanvas();
}
public void startApp()
{
display_ = Display.getDisplay(this);
display_.setCurrent(canvas_);
canvas_.repaint();
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command c, Displayable s)
{
}
}