📄 tool.java
字号:
/**
*工具类
*@CopyRight:Move2008
*@Author:bedlang
*@Version 1.0 2003/7/17
*/
package move.util;
import javax.microedition.lcdui.*;
public class Tool
{
/**
*得分一个字符串的绘画长度
*/
public static int getStrWidth(String str)
{
Font font=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_SMALL);
return font.stringWidth(str);
}
/**
* 获得当前字符串指定字段的内容
* @param 原字符串
* @param fieldNo 字段编号(第一个字段的编号是1)
* @param separatorChar 字符串中用来分隔字符的符号
* @return 当前字符串的指定字段的内容
*/
public static String getField(String str, int fieldNo, String separatorChar) {
int bi = beginIndexOfField(str, fieldNo, separatorChar);
if (bi==-1){
return str;
}
int ei = endIndexOfField(str, fieldNo, separatorChar);
return str.substring(bi,ei);
}
// 字段的开始位置
// 如果超出范围,返回-1
public static int beginIndexOfField(String f, int n, String separatorChar){
if (n<1) {
return -1;
} else if(n==1){
return 0;
} else {
int j = 0;
int i = 1;
while(true){
j = f.indexOf(separatorChar,j);
i++;
if (j==-1){
return -1;
} else {
j += separatorChar.length();
if (i==n) {
return j;
}
}
}
}
}
// 字段的结束位置
// 如果超出范围,返回-1
public static int endIndexOfField(String f, int n, String separatorChar){//??
if (n<1) {
return -1;
} else {
int i = 0;
int j = 0;
while(true){
j = f.indexOf(separatorChar,j);
i++;
if(j==-1){
return f.length();
} else {
if (i==n) {
return j;
}
j += separatorChar.length();
}
}
}
}
public static int getTrialTimes(String dbName, int allTimes)
{
RecordDB db = new RecordDB();
db.open(dbName);
int times=0;
if(db.getNumRecords()==0)
{
times = allTimes-1;
db.addRecord(String.valueOf(times));
}
else
{
times = Integer.valueOf(db.getRecord(1)).intValue();
times--;
if(times>0)
db.setRecord(1,String.valueOf(times));
}
db.close();
return times;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -