制作程序启动画面
文章信息
Contents |
Introduction
Splash界面对于小的MIDlet来说不一定是需要的,但是从美观的角度,以及一些大的应用,需要一定的时间来加载资源,在这种情况下,启动界面就变得非常有价值了。 本文演示了如何创建一个图片的启动界面,程序启动时,自动加载显示,然后一定时间后,自动消失,从而进入程序主界面。
实现
- 我们在一个Canvas的子类中来显示Splash的 图片, Image image由参数传入。
- 图片的描画:
-
protected void paint(Graphics g) {
g.setColor(this.color);
g.fillRect(0x00, 0x00, getWidth(), getHeight());
if (this.image != null) {
g.drawImage(this.image, this.centerX, this.centerY, 0x00);
}
}
-
- 显示时间设定, 这里设定了时间3S, 3s后显示设置display 为主界面,结束Splash
-
public void show(final Display display, final Displayable next,
final long millis) {
display.setCurrent(this);
// Schedule next Displayable
Thread t = new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
display.setCurrent(next);
}
}
});
t.start();
}
-
- 设置Splash 图片
-
protected void startApp() throws MIDletStateChangeException {
this.display = Display.getDisplay(this);
this.splash = new Splash("/splash_240x400.png", 0xFFFFFF);
this.exit = new Command("Exit", Command.EXIT, 0x01);
Displayable main = this.getMainScreen();
main.setCommandListener(this);
main.addCommand(this.exit);
this.splash.show(this.display, main, 3000);
}
-
例程下载



(no comments yet)