//實現按任意鍵進進主界面
import Javax.microedition.lcdui.*;
public class WelcomeCanvas extends Canvas{
//背景圖片
Image bgImage = null;
Display display;
public WelcomeCanvas(Display display){
this.display = display;
//導進圖片
try{
bgImage = Image.createImage("/res/welcome.png");
}catch(Exception e){
Alert a = new Alert("錯誤","資源文件不存在!",null,AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
//顯示提示框
display.setCurrent(a);
}
}
protected void paint(Graphics g) {
//繪制背景圖片
g.drawImage(bgImage,0,0,Graphics.TOP | Graphics.LEFT);
}
protected void keyPressed(int keyCode){
//顯示需要顯示的界面
display.setCurrent(new MainList());
}
}
//實現等候5秒以後主動進進主界面
import Javax.microedition.lcdui.*;
public class WelcomeCanvas extends Canvas implements Runnable {
//背景圖片
Image bgImage = null;
Display display;
public WelcomeCanvas(Display display){
this.display = display;
//導進圖片
try{ bgImage = Image.createImage("/res/welcome.png");
}catch(Exception e){
Alert a = new Alert("錯誤","資源文件不存在!",null,AlertType.ERROR);
a.setTimeout(Alert.FOREVER);
//顯示提示框
display.setCurrent(a);
}
//啟動線程
Thread thread = new Thread(this);
thread.start();
}
protected void paint(Graphics g) {
//繪制背景圖片
g.drawImage(bgImage,0,0,Graphics.TOP | Graphics.LEFT);
}
public void run(){
//等候3秒
try{
Thread.sleep(5000);
}catch(Exception e){
}
//顯示需要顯示的界面
display.setCurrent(new MainList());
}
}