用j2me开发的电子书

bernieli 2008-06-24 10:42:04
谁有用j2me开发的电子书的源代码,请给我一份,告诉我怎么做也行,谢谢各位喽。
...全文
172 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongxiaohan 2011-02-10
  • 打赏
  • 举报
回复
http://edu.gamfe.com/b/c330.html
这里有很多J2ME的电子书 自己寻找下吧
singmj 2008-07-07
  • 打赏
  • 举报
回复
高,不看不知道,要注意字体大小不同的,受教了,谢谢
shanxmxj 2008-06-27
  • 打赏
  • 举报
回复
期待中...
哪位大哥有的话顺便也给我发一下
shanxmxj@163.com
谢谢了。
pipi_jf 2008-06-27
  • 打赏
  • 举报
回复
直接上代码吧:



/**@todo 对一段文字进行分行,这种分行是针对于某个字体的
* @author efei
* @param strSource String 待分行的字符串
* @param font Font 使用的字体
* @param width int 分行后需要满足的宽度
* @param strSplit String 断词判断字符,如空格和一些标点符号。中文不需要断词,则传空字符串
* @return Vector
*/
public 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;
}



使用示例:


int gintLineHeight = 15;//全局变量,行高
int gintBeginIndex = 0;//全局变量,在keyPressed里改变它的值,便可以实现上下翻页

String str = "方便起见,可以定义一个行高作为全局变量,这样比较好,写个简单的例子:"
Vector vector = getSubsection(str,Font.getDefaultFont(),getWidth(),"");

for(int i=gintBeginIndex;i<vector.size();i++){
g.drawString((String)vector.elementAt(i),0,gintLineHeight*i,0);
if((i-mintBeginIndex+1)*gintLineHeight>getHeight())break;
}
vector = null;

bernieli 2008-06-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 pipi_jf 的回复:]
电子书本身没什么难度,注意文字的分行算法。
[/Quote]

能否把文字分行的算法说的详细些。
pipi_jf 2008-06-24
  • 打赏
  • 举报
回复
电子书本身没什么难度,注意文字的分行算法。

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧