📄 tool.java
字号:
/**
*工具类
*@CopyRight:Move2008
*@Author:bedlang
*@Version 1.0 2003/7/17
*/
package mmae.util;
import javax.microedition.lcdui.*;
import java.io.*;
import java.util.*;
public class Tool
{
/**
*得分一个字符串小字体的绘画长度
*/
public static int getStrWidth(String str)
{
int w=0;
Font font=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_SMALL);
if(str==null)
w=0;
else
w=font.stringWidth(str);
return w;
}
/**
*得分一个字符串的绘画长度
*/
public static int getStrWidth(String str, int FontSize)
{
int w=0;
Font font=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,FontSize);
if(str==null)
w=0;
else
w=font.stringWidth(str);
return w;
}
/**
* 得到当前字体的高度
*/
public static int getFontHeight()
{
Font font=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_SMALL);
return font.getHeight();
}
/**
* 取出Str字符串的某个字段值,FieldNo为字段号(起始位置为1),SeparatorChar为字段分隔符
*/
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();
}
}
}
}
/**
*得到试用版本剩余的使用次数,dbName为数据库名字,allTimes为总试用次数
*/
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;
}
/**
*得到当前日期,chr为数字间的间隔符,如2003-08-31中的'-'
*/
public static String getDate(String chr)
{
Calendar cal= Calendar.getInstance();
return cal.get(Calendar.YEAR) + chr + cal.get(Calendar.MONTH) + chr + cal.get(Calendar.DATE);
}
/**
*得到当前时间
*/
public static long getTime()
{
Date d = new Date();
return d.getTime();
}
/**
*计算时间间隔
*/
public static int getDays(Date sd,Date ed){
return (int)(ed.getTime()-sd.getTime())/(3600*24*1000);
}
/**
*得到整数
*/
public static int toInt(String Value)
{
if(Value.trim().length()==0)
return 0;
return Integer.valueOf(Value).intValue();
}
/**
打印
*/
public static void println(String str)
{
System.out.println(str);
}
/**
打印
*/
public static void println(int i)
{
System.out.println(i);
}
/**
打印
*/
public static void print(String str)
{
System.out.print(str);
}
public static String toUTF(byte[] serverData,int httpLen)
{
//UTF-8 解码
String str;
char []infoStr = new char[httpLen*2];
char ch;
int i = 0;
int charCount = 0;
while( i < httpLen )
{
try
{
if ( ( serverData[i] & 0x80 ) != 0)
{
if ( (serverData[i] & 0x20) != 0 )
{
ch = (char)((serverData[i]&0xf) << 12);
ch += (char)(serverData[i+1]&0x3f)<<6;
ch += serverData[i+2]&0x3f;
i+=3;
}
else
{
ch = (char)((serverData[i]&0x1f) << 6);
ch += serverData[i+1]&0x3f;
i+=2;
}
}
else
{
ch = (char)serverData[i];
i++;
}
infoStr[charCount++] = ch;
}
catch ( Exception e )
{
}
}
return new String( infoStr, 1, charCount );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -