📄 stringlayout.java
字号:
/**
*字符串布局类
*@CopyRight:Move2008
*@Author:bedlang
*@Version 1.0 2003/7/20
*/
//Download by http://www.codefans.net
package move.ui;
import javax.microedition.lcdui.*;
import move.util.Tool;
public class StringLayout extends Base
{
int layoutWidth;
int lineGap;
String text;
int fontHeight;
int line;
/**
*构造函数
*@param Str:布局中的字符串
*@param X:布局的左上角位置
*@param Y:布局的右上角位置
*@param LayoutWidth:布局宽度
*@param Gap:各行之间的空隙
*/
public StringLayout(String Str, int X, int Y, int LayoutWidth, int Gap)
{
setPosition(X, Y);
text = Str;
layoutWidth = LayoutWidth;
lineGap = Gap;
int begin = 0;
String s = "";
Font font=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_BOLD,Font.SIZE_SMALL);
fontHeight = font.getHeight();
line = 0;
for(int i=0;i<text.length();i++)
{
char ch = text.charAt(i);
if (Tool.getStrWidth(text.substring(begin,i))>=layoutWidth || i==text.length() || ch=='\n')
{
if(ch=='\n')
begin = i+1;
else
begin = i;
line ++;
}
}
}
public void draw(Graphics g, int X, int Y)
{
setPosition(X,Y);
draw(g);
}
public void draw(Graphics g)
{
int begin = 0;
String s = "";
line = 0;
for(int i=0;i<text.length();i++)
{
char ch = text.charAt(i);
if (Tool.getStrWidth(text.substring(begin,i))>=layoutWidth || i==text.length() || ch=='\n')
{
s = text.substring(begin,i);
g.drawString(s, left, top+line*(fontHeight+lineGap), g.TOP|g.LEFT);
if(ch=='\n')
begin = i+1;
else
begin = i;
line ++;
}
}
}
public int getWidth()
{
return layoutWidth;
}
public int getHeight()
{
return fontHeight*line + lineGap*line;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -