请参考java.util.TimerTask.

TimerTask is something like Timer in VisualBasic. You can sepcify a time period in milliseconds

for your requirement"一幅LOGO显示完以后,几秒种自动显示下一幅LOGO".
Here is an sample code.

public void testTimer() {
MyTimerTask myTimerTask = new MyTimerTask();
Timer timer = new Timer();
timer.schedule(myTimerTask, 5000, 10000); //wait for 5 seconds and then call the function every 

10 seconds
}

class MyTimerTask extends TimerTask {
public void run() {
//This method will be called every 10 Seconds

Image im = Image.createImage(imageData, 0, imageData.length);
if(im == null)
System.out.println("NULL IMAGE");
System.out.println("The Size of the Byte Array is:" +imageData);
if(frm.size() > 0)
for(int i = 0; i < frm.size(); i++)
frm.delete(i);
frm.append(im);
disp.setCurrent(frm);

}
}

另外,对于你所说的是不是应该叫做SplashScreen,那么国外曾经有人给出这么一个例子,虽然不是周期性地显示一张又一张的图片,而是利用TimerTask周期性地repaint画布,画出一种Splash Screen的感觉,你可以参考:

import java.util.*;

import javax.microedition.lcdui.*;

public class WaitCanvas
extends Canvas {
private int mCount, mMaximum;
private int mInterval;

private int mWidth, mHeight, mX, mY, mRadius;
private String mMessage;

public WaitCanvas() {
mCount = 0;
mMaximum = 36;
mInterval = 100;

mWidth = getWidth();
mHeight = getHeight();

// Calculate the radius.
int halfWidth = (mWidth - mRadius) / 2;
int halfHeight = (mHeight - mRadius) / 2;
mRadius = Math.min(halfWidth, halfHeight);

// Calculate the location.
mX = halfWidth - mRadius / 2;
mY = halfHeight - mRadius / 2;

// Create a Timer to update the display.
TimerTask task = new TimerTask() {
public void run() {
mCount = (mCount + 1) % mMaximum;
repaint();
}
};
Timer timer = new Timer();
timer.schedule(task, 0, mInterval);
}

public void setMessage(String s) {
mMessage = s;
repaint();
}

public void paint(Graphics g) {
int theta = -(mCount * 180 / mMaximum);


// Clear the whole screen.
g.setColor(255, 255, 255);
g.fillRect(0, 0, mWidth, mHeight);

// Now draw the pinwheel.
g.setColor(0, 0, 0);

g.drawArc(mX, mY, mRadius, mRadius, 0, 360);

g.fillArc(mX, mY, mRadius, mRadius, theta + 20, 20);
//g.fillArc(mX, mY, mRadius, mRadius, theta + 60, 60);
//g.fillArc(mX, mY, mRadius, mRadius, theta + 90, 90);
//g.fillArc(mX, mY, mRadius, mRadius, theta + 120, 120);

// Draw the message, if there is a message.
if (mMessage != null)
g.drawString(mMessage, mWidth / 2, mHeight,
Graphics.BOTTOM | Graphics.HCENTER);
}
}

上面那个是利用TimerTask自动定时填充图形来展示Splash Screen的,那么下面这个就是显示图片来Splash Screen了:

import java.util.*;
import javax.microedition.lcdui.*;

public class Splash extends Canvas {

private Display display;
private Displayable next;
private Timer timer=new Timer();

public Splash (Display display,Displayable next) {
this.display=display;
this.next=next;
display.setCurrent(this);
}

protected void showNotify () {
timer.schedule( new TimerTask () { public void run() {
displayNext(); }},8000);
}

protected void hideNotify() {
timer.cancel();
}

protected void keyPressed (int keycode) {
displayNext();
}

protected void pointerPressed (int x, int y) {
displayNext();
}

private void displayNext() {
display.setCurrent(next);


protected void paint (Graphics g) {
int height=this.getHeight();
int width=this.getWidth();

// fill background as white
g.setColor(0xFFFFFF);
g.fillRect(0,0,width,height);

Image logo=null;
try {
logo=Image.createImage("/images/logo.png");
} catch (Exception ignore) {}

g.drawImage(logo,width/2,height/2,g.HCENTER|g.VCENTER);
}



here's the calling method in your midlet(it passes the Display and current Displayable):

/** *//**
* This shows the splash
*/

private void showSplash () {
new Splash (display,MenuList); 
}

还有一种办法是利用currentTimeMillis。
无非就是利用System.currentTimeMillis()+2000先行计算出什么时间该显示

后一幅图片了,如果靠while循环不断检测发现时间到了,就换那张图片。

private boolean showImage;


void someMethod()
{
long time = System.currentTimeMillis()+2000;

showImage = true;
while(System.currentTimeMillis()<time)
{
repaint();
serviceRepaints();
}
showImage = false;
}

public void paint()
{

if(showImage)
g.drawImage(img,offsetX,MAX_Y/2,g.LEFT|g.VCENTER);
}

efei说:
“你要做的无非就是一个延时,过一定时间就换一幅图片。至于怎么来判断这个延时,方法多种多样,用线程,用TimerTask,用System.currentTimeMillis(),基本上都一样

个人比较倾向于使用线程作为固定的时钟脉冲来驱动游戏。

对于System.currentTimeMillis(),我只能告诉你两点,一是它的作用是取得当前时间,二呢,用这个方法如果只是简单比较时间,那么如果中断游戏,过一段时间再恢复,就会存在问题。

[JavaME]利用java.util.TimerTask来做Splash Screen的N种方法相关推荐

  1. java实现自动任务_Java实现定时任务的三种方法

    普通thread 这是最常见的,创建一个thread,然后让它在while循环里一直运行着,通过sleep方法来达到定时任务的效果.这样可以快速简单的实现,代码如下: public class Tas ...

  2. java web ip_详解Java Web如何限制访问的IP的两种方法

    前一阵子因为在做项目时碰到了这个功能,现在好好总结一下,至于为什么要限制IP访问,我就不多说了.然后百度了一下,现在主要有两种方式去限制IP访问,第一种是最简单的方便的,第二种是通过过滤器来限制访问. ...

  3. 将Java应用程序本地编译为EXE的几种方法

    将Java应用程序本地编译为EXE的几种方法(推荐使用JOVE和JET)   1. 从[url]www.towerj.com[/url]获得一个TowerJ编译器,该编译器可以将你的CLASS文件   ...

  4. Java中字符串中子串的查找共有四种方法(indexof())

    2019独角兽企业重金招聘Python工程师标准>>> public class FirstDemo { /** *API中String的常用方法 */ // 查找指定字符串是否存在 ...

  5. java中char类型转换成int类型的两种方法

    java中char类型转换成int类型的两种方法 方法一: 第一种利用Integer包装类的方法Integer.parseInt Copychar ch = '9'; if (Character.is ...

  6. 【转】Java中字符串中子串的查找共有四种方法(indexof())

    原文网址:http://wfly2004.blog.163.com/blog/static/1176427201032692927349/ Java中字符串中子串的查找共有四种方法,如下: 1.int ...

  7. java double类型保留两位小数的几种方法

    java double类型保留两位小数的几种方法 返回double类型的(转换比较方便) ①能四舍五入 double d = 114.145; d = (double) Math.round(d * ...

  8. JAVA 通过value获取Map中key的三种方法

    JAVA 通过value获取Map中key的三种方法 简介 方法描述 循环法 Stream方法 Apache Commons Collections的BidiMap 总结 简介 我们都知道Map是存放 ...

  9. 利用java.util.logging.Logger输出日志

     log4j提供了非常灵活而又强大的日志功能,java运行库中的日志功能反而被忽略了.其实也是挺好用的,最重要的是,用这个的话就不再需要log4j的jar文件. 由于java.util.loggi ...

最新文章

  1. 用户信息填写web代码_基于web的自定义表单引擎
  2. FPGA中时钟相关概念
  3. adguard没有核心 core no_Spring 核心组件原理解析
  4. 一文看懂家庭宽带光纤是如何入户
  5. 安装Oracle数据库操作步骤
  6. [asp.net] 利用WebClient上传图片到远程服务
  7. 15个问题告诉你如何使用Java泛型
  8. 程序员如何成为编程高手并以此创业
  9. 热门事件和书籍中资料管理中国
  10. mysql之 mysql_config_editor/login-path 登录密码保护
  11. 2020年考研准考证打印下载及注意事项
  12. 最新的紫猫编程学院从零开始学脚本值得学习吗
  13. VS高版本兼容XP系统
  14. js禁止输入框输入特殊符号或emoji表情
  15. 数据分析实战(二) 基于美国人口adult数据集R语言分析实战
  16. 如何网络推广快,怎么快速推广网站
  17. 基于STM32F407使用ADC采集电压实验
  18. Nginx之URL重写
  19. 微信支付的架构到底有多牛?
  20. 电商产品展示,选360°全景还是3D展示?

热门文章

  1. 正坐标系及矢量知识,点乘与差乘,旋转
  2. python vtk实时更新点云_Python-VTK:点云和颜色b
  3. 华中科技大学计算机暑期夏令营,2019年华中科技大学计算机专业夏令营
  4. 线索二叉树是一种什么结构_技术面试之常用的数据结构
  5. 定位会完全压住标准流盒子里面的内容(HTML、CSS)
  6. 文本格式化标签(HTML)
  7. HoloLens 2开发:Pcx 渲染点云单眼显示问题
  8. PCL之区域生长分割
  9. 电影推荐系统 python简书_分析9000部电影|一个简单的电影推荐系统
  10. java水仙花数代码_java知识分享篇(五)