📄 splash.java
字号:
/**
*闪屏类
*@CopyRight:eshouji.com
*@Author:ceze
*@Version 1.0 2004/4/22
*/
package vitular.ui;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import java.io.*;
/**
*
* <p>Title: 闪屏</p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Splash
extends MsgCtrlBase
implements Runnable {
private final int STATUS_BUSY = 101;
private final int STATUS_IDLESSE = 102;
private final int HOLD_TIME = 1000;
private Image splashImg; //闪屏图像
private Hourglass hourgla; //沙漏
private Thread thread = null;
//private Media backSoundMedia;
private String appVersion;
private int interval = 50; //刷新间隔
private boolean stopthread = true;
private boolean pausethread = true;
// private Graphics g;
private int status;
private Player player; //背景音效播放器
/**
* 构造函数
* @param splashImgName String 底图名称
* @param mediaName String 背景音效名称
* @param Version String 版本信息
*/
public Splash(MsgCanvas canvas, String splashImgName, String mediaName, String waitString, String Version) {
super(canvas, 0, 0, canvas.getWidth(), canvas.getRealHeight());
appVersion = Version;
try {
splashImg = Image.createImage(splashImgName);
posX = (width - left - splashImg.getWidth()) >> 1;
posY = (height - top - splashImg.getHeight()) >> 1;
hourgla = new Hourglass(canvas, 0, 0, width, height);
if (waitString != null){
this.setWaitString(waitString);
}
if (mediaName != null) {
player = Manager.createPlayer(mediaName);
if (player != null) {
player.setLoopCount(-1);
player.start();
}
}
}
catch (Exception e) {
}
status = STATUS_BUSY;
}
/**
*Splash默认的线程方式,通过start方法可以启动它
*/
public void run() {
Graphics g = canvas.getPaintG();
if (interval == 0) {
update(g);
}
else {
while (!stopthread) {
//System.out.println("splash thread");
while (!pausethread) {
try {
if(status == STATUS_BUSY){
if (stopthread) {
continue;
}
//System.out.println("splash update!!!!!!!!!!!!!!!!!!");
update(g);
thread.sleep(interval);
}
else if(status == STATUS_IDLESSE)
{
thread.sleep(HOLD_TIME);
this.destroy();
}
}
catch (InterruptedException e) {
System.out.println("XCanvas Thread Error:" + e.getMessage());
}
} //~end stopthread
} //~end killthread
} //~end else
kill();
}
/**
* 设置闪屏文字
* @param str String
*/
public void setWaitString(String str){
if (hourgla != null) {
hourgla.setWaitString(str);
}
}
protected void updateSelf(Graphics graphics) {
try {
graphics.setClip(0, 0, width, height);
graphics.drawImage(splashImg, posX, posY, Graphics.LEFT | Graphics.TOP);
graphics.setColor(0XFFFFFF);
graphics.drawString(appVersion, left + 1, top + 1, Graphics.TOP | Graphics.LEFT);
if (status == STATUS_BUSY) {
if (hourgla != null) {
hourgla.update(graphics);
// System.out.println("update hourgla");
}
// System.out.println("splash update");
}
canvas.flushGraphics();
}
catch (Exception e) {
System.out.println(e.toString());
}
}
/**
*Splash的线程启动,Interval为线程跳动的间隙时间,即每过Interval时间XCavans就会自动调用update方法
*/
public void startSplash(int Interval) {
interval = Interval;
startSplash();
}
/**
**Splash的线程启动,以默认时间间隔调用启动update方法
*/
public void startSplash() {
pausethread = false;
stopthread = false;
thread = new Thread(this);
thread.start();
}
/**
* 结束闪屏
*/
protected void stopSplash() {
// stopthread = true;
status = STATUS_IDLESSE;
hourgla = null;
update(canvas.getPaintG());
System.out.println("stop hourla");
}
/**
*线程暂停
*/
public void pause() {
pausethread = true;
}
/**
*线程休眠n毫秒
*/
public void sleep(int Time) {
try {
this.wait(Time);
}
catch (Exception e) {}
}
/**
* 结束线程
*/
public void kill() {
pausethread = true;
stopthread = true;
thread = null;
}
/**
* 销毁自身
*/
protected void destroy() {
kill();
splashImg = null;
appVersion = null;
if (player != null) {
try {
player.stop();
player = null;
}
catch (Exception e) {}
}
System.gc();
dispatchEvent(EVT_SPLASH_CLOSE, 0, null);
}
/**
*线程恢复
*/
public void resume() {
pausethread = false;
}
public void keyPressed(int code) {
if (STATUS_BUSY == status) {
return;
}
//发送splash关闭消息
if (code != MsgCanvas.KEY_SEND && code != MsgCanvas.KEY_END) {
destroy();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -