?? imagenumber.java
字號:
package com.j2medev.chapter5;
import javax.microedition.lcdui.*;
/***********************************
* 類功能:圖像的方式顯示數(shù)字
***********************************/
public class ImageNumber {
private Image imgNumber;
/******************************************
* 函數(shù)功能:構(gòu)造函數(shù)
* 參數(shù):圖片文件名
* 返回值:
******************************************/
public ImageNumber(String filename) {
try {
imgNumber = Image.createImage(filename);
}
catch(Exception e) {}
}
/******************************************
* 函數(shù)功能:在指定位置上畫出數(shù)字
* 參數(shù):Graphics對象, 待顯示數(shù)字, 橫座標(biāo), 縱座標(biāo)
* 返回值:無
******************************************/
public void draw(Graphics g, int number, int x, int y) {
if (imgNumber == null) {
return;
}
final int numberWidth = imgNumber.getWidth() / 10; // 數(shù)字寬度
final int numberHeight = imgNumber.getHeight(); // 數(shù)字高度
// 把待顯示的數(shù)字變成字符串
final String szNumber = Integer.toString(number);
int pX = x; // 待顯示位置的橫座標(biāo)
for (int i = 0; i < szNumber.length(); i++) {
g.setClip(pX, y, numberWidth, numberHeight);
try {
g.drawImage(imgNumber, pX - (szNumber.charAt(i) - 48) * numberWidth, y,
Graphics.TOP | Graphics.LEFT);
}
catch(Exception e) {}
pX += numberWidth;
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -