?? utils.java
字號:
package opusmicro.demos.game;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import javax.microedition.lcdui.Font;
public class Utils {
public static final String getTimeZone(){
Calendar calendar = Calendar.getInstance();
Date date = new Date(System.currentTimeMillis());
calendar.setTime(date);
int day = calendar.get(Calendar.DATE);
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH)+1;
int hour = calendar.get(Calendar.HOUR);
int minute = calendar.get(Calendar.MINUTE);
int second = calendar.get(Calendar.SECOND);
System.out.println(year+"-"+month+"/-"+day+" "+hour+":"+minute+":"+second);
return year+"-"+month+"/-"+day+" "+hour+":"+minute+":"+second;
}
public static final Vector getSubsection(String strSource, Font font, int width, String strSplit) {
Vector vector = new Vector();
String temp = strSource;
int i, j;
int LastLength = 1;
int step = 0;
try {
while ( !temp.equals("")) {
i = temp.indexOf("\n");
if ( i > 0) {
if ( font.stringWidth(temp.substring(0, i - 1)) >= width) {
i = -1;
}
}
if ( i == -1) {
if ( LastLength > temp.length()) {
i = temp.length();
}
else {
i = LastLength;
step = font.stringWidth(temp.substring(0, i)) > width ? -1 : 1;
// 得到臨界點
if ( i < temp.length()) {
while ( !(font.stringWidth(temp.substring(0, i)) <= width && font.stringWidth(temp
.substring(0, i + 1)) > width)) {
i = i + step;
if ( i == temp.length()) break;
}
}
}
// 斷詞,如果需要的話
if ( !strSplit.equals("")) {
j = i; // 把初始值記錄下來,是因為有可能出現一種情況,這種情況就是這一行只有這么一個單詞,會一直搜索到頭
if ( i < temp.length()) {
while ( strSplit.indexOf(temp.substring(i - 1, i)) == -1) {
i--;
if ( i == 0) {
i = j; // 恢復
break;
}
}
}
}
}
LastLength = i;
vector.addElement(temp.substring(0, i));
if ( i == temp.length()) {
temp = "";
}
else {
temp = temp.substring(i);
if ( temp.substring(0, 1).equals("\n")) {
temp = temp.substring(1);
}
}
}
}
catch (Exception e) {
System.out.println("getSubsection:" + e);
}
return vector;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -