?? animecanvas.java
字號(hào):
/*
* AnimeCanvas.java
*
* Copyright 2001 SkyArts. All Rights Reserved.
*/
import javax.microedition.lcdui.*;
/**
* Anime的描繪與操作所用的類
*
* @version 1.0
*/
class AnimeCanvas extends Canvas implements Runnable {
/** 儲(chǔ)存動(dòng)畫(huà)的圖像Index的變量 */
private int imgInx;
/** 儲(chǔ)存動(dòng)畫(huà)的圖像的變量 */
private Image[] imgs;
/** 用來(lái)將動(dòng)畫(huà)描繪線程停止的標(biāo)志變量 */
private boolean isStopped;
/** 構(gòu)造函數(shù) */
AnimeCanvas() {
//取得標(biāo)題圖像
imgs = new Image[3];
for(int i=0; i < imgs.length; i++) {
try {
imgs[i] = Image.createImage("/img" + String.valueOf(i) + ".png");
}catch(java.io.IOException e) {}
}
//開(kāi)始描繪線程
doStart();
}
/** 啟動(dòng)動(dòng)畫(huà)線程的方法 */
private void doStart() {
isStopped = false;
Thread th = new Thread(this);
th.start();
}
/** 停止動(dòng)畫(huà)線程的方法 */
private void doStop() {
isStopped = true;
}
/** 動(dòng)畫(huà)線程處理部分 */
public void run() {
imgInx = 0;
while(! isStopped) {
try {
repaint(); //再描繪
Thread.sleep(500); //等待一定時(shí)間
imgInx++; //改變圖像的Index
if(imgInx >= imgs.length) {
imgInx = 0;
}
}catch(InterruptedException e){}
}
}
/** 進(jìn)行描繪的方法 */
protected void paint(Graphics g) {
//將背景以白色清除
g.setColor(0x00FFFFFF);
g.fillRect(0, 0, getWidth(), getHeight());
//描繪指定Index的圖像
g.drawImage(imgs[imgInx], 0, 0, Graphics.TOP|Graphics.LEFT);
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -