?? loadingcanvas.java
字號:
import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
/**
* @author trojan
*
* ??????????????????
*/
public class LoadingCanvas extends Canvas implements Runnable {
private boolean isLoading = true;// ????????????
private int loadingIndex = 0;// ???????????
private Image loadingImage;// ??????
private String percent = "";// ??????????
// ??????,?????
public LoadingCanvas() {
setFullScreenMode(true);
initialize();
new Thread(this).start();
}
// ?????????
protected void initialize() {
// ?????????
loadingImage = createImage("/images/jg07.gif");
}
public void run() {
// ?????????,?????Loading????
while (isLoading) {
repaint();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO ?????? catch ??
e.printStackTrace();
}
}
}
// ???????
protected void paint(Graphics g) {
g.drawImage(loadingImage, getWidth() / 2, getHeight() / 2,
Graphics.HCENTER | Graphics.VCENTER);
g.setColor(0xffffffff);
Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
Font.SIZE_LARGE);
g.setFont(font);
switch (loadingIndex) {
case 0:
g.drawString("Loading", (getWidth() / 2) - 35,
getHeight() / 2 + 30, Graphics.LEFT | Graphics.TOP);
break;
case 1:
g.drawString("Loading.", (getWidth() / 2) - 35,
getHeight() / 2 + 30, Graphics.LEFT | Graphics.TOP);
break;
case 2:
g.drawString("Loading..", (getWidth() / 2) - 35,
getHeight() / 2 + 30, Graphics.LEFT | Graphics.TOP);
break;
case 3:
g.drawString("Loading...", (getWidth() / 2) - 35,
getHeight() / 2 + 30, Graphics.LEFT | Graphics.TOP);
break;
}
loadingIndex = (loadingIndex + 1) % 4;
if (!(percent.equals(""))) {
g.drawString(percent, getWidth() / 2, getHeight() / 2 + 50,
Graphics.HCENTER | Graphics.TOP);
}
}
// ??????
protected Image createImage(String path) {
Image image = null;
try {
image = Image.createImage(path);
} catch (IOException e) {
// TODO ?????? catch ??
e.printStackTrace();
}
return image;
}
// ??????
public void endLoading() {
isLoading = false;
}
// ?????????????
public void setPercent(String percent) {
this.percent = percent;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -