×
Namespaces

Variants
Actions

制作程序启动画面

From Nokia Developer Wiki
Jump to: navigation, search
WP Metro Icon Chinese.png
Article Metadata

代码示例
兼容于
平台:
Series 40

文章
Amazing1100 在 09 Jul 2012 创建
最后由 hamishwillee 在 09 Aug 2013 编辑

Contents

Introduction

Splash界面对于小的MIDlet来说不一定是需要的,但是从美观的角度,以及一些大的应用,需要一定的时间来加载资源,在这种情况下,启动界面就变得非常有价值了。 本文演示了如何创建一个图片的启动界面,程序启动时,自动加载显示,然后一定时间后,自动消失,从而进入程序主界面。


Splash 240x400.png

实现

  1. 我们在一个Canvas的子类中来显示Splash的 图片, Image image由参数传入。
    public class Splash extends Canvas {
     
    private Image image;
    private int color;
    private int centerX;
    private int centerY;
    ...............
    }
  2. 图片的描画:
    	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);
    }
    }
  3. 显示时间设定, 这里设定了时间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();
    }
  4. 设置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);
    }

例程下载


相关链接

This page was last modified on 9 August 2013, at 07:35.
108 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×