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());
} }