private String info; private String info_wrap[];
package com.token.util;
import java.util.Vector;
import javax.microedition.lcdui.Font;
public class StringDealMethod {
public StringDealMethod()
{
}
// 字符串切割,实现字符串自动换行
public static String[] format(String text, int maxWidth, Font ft) {
String[] result = null;
Vector tempR = new Vector();
int lines = 0;
int len = text.length();
int index0 = 0;
int index1 = 0;
boolean wrap;
while (true) {
int widthes = 0;
wrap = false;
for (index0 = index1; index1 < len; index1++) {
if (text.charAt(index1) == '\n') {
index1++;
wrap = true;
break;
}
widthes = ft.charWidth(text.charAt(index1)) + widthes;
if (widthes > maxWidth) {
break;
}
}
lines++;
if (wrap) {
tempR.addElement(text.substring(index0, index1 - 1));
} else {
tempR.addElement(text.substring(index0, index1));
}
if (index1 >= len) {
break;
}
}
result = new String[lines];
tempR.copyInto(result);
return result;
}
public static String[] split(String original, String separator) {
Vector nodes = new Vector();
//System.out.println("split start...................");
//Parse nodes into vector
int index = original.indexOf(separator);
while(index>=0) {
nodes.addElement( original.substring(0, index) );
original = original.substring(index+separator.length());
index = original.indexOf(separator);
}
// Get the last node
nodes.addElement( original );
// Create splitted string array
String[] result = new String[ nodes.size() ];
if( nodes.size()>0 ) {
for(int loop=0; loop<nodes.size(); loop++)
{
result[loop] = (String)nodes.elementAt(loop);
//System.out.println(result[loop]);
}
}
return result;
}
}
int width = getWidth();
Font ft = Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_LARGE);
info = "欢迎使用!\n"
+"1 MVC测试;\n"
+"2 自动换行测试,绘制可自动识别换行的字符串。\n";
info_wrap = StringDealMethod.format(info, width-10, ft);
int width = getWidth();
Font ft = Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_LARGE);
info = "欢迎使用!\n"
+"1 MVC测试;\n"
+"2 自动换行测试,绘制可自动识别换行的字符串。\n";
info_wrap = StringDealMethod.format(info, width-10, ft);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有