`
wanchong998
  • 浏览: 232840 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

LWUIT 一些细节疑难杂症整理笔记

阅读更多

1、textArea 显示文本内容,在部分手机上无法显示全部内容,每一行的最后几个字被挡住
琢磨了很久终于找了出来,解决方案如下:
TextArea txtContent = new TextArea(strContent, 12, 24);
//添加这一句即可
txtContent.setWidestChar('一');
2、若要对文本框中的内容设置补丁:
txtContent.getStyle().setPadding(Component.RIGHT, 10);
内容往右10像素。
3、如果list上不想要显示文字多余时的省略号
name.setEndsWith3Points(false);
4、重写Dialog要让标题与Form的样式一致
dialog.show(100, 100,100,100, true);
5、声音播放
try {
InputStream is = getClass().getResourceAsStream(
"/res/NewMailSound.wav");
Player player = Manager.createPlayer(is, "audio/x-wav");
player.start();
} catch (Exception e) {
e.printStackTrace();
}
6、使得TextField也能够在触屏手机上点击时出现输入编辑
解决方法:
在TextField源码上 加上editString();函数:
public void pointerReleased(int x, int y) {
// unlike text area the text field supports shifting the cursor with the touch screen
editString();
String text = getText();
int textLength = text.length();
int position = 0;
Font f = getStyle().getFont();
x -= getAbsoluteX();
for(int iter = 0 ; iter < textLength ; iter++) {
int width = f.substringWidth(text, 0, iter);
if(x > width) {
position = iter;
} else {
break;
}
}
if(position == textLength - 1) {
if(f.stringWidth(text) < x) {
position = textLength;
}
}
setCursorPosition(position);
repaint();
}
或者官方的解决方法:http://forums.java.net/jive/thread.jspa?threadID=52716
7、震动
public void MakeVibrate() {
new Thread() {
public void run() {
try {
Display.getInstance().vibrate(2000);
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
8、导致内存激增的原因(可以用自动模拟器的内存检测器进行监测C:\WTK2.5.2\bin\prefs.exe将你要的设置勾选)
而lwuit里面的源码有两句是会导致内存一直占用,一个是TextField中的这段代码

view plaincopy to clipboardprint?
// public boolean animate() {
// boolean ani = super.animate();
// if (hasFocus()) {
// long currentTime = System.currentTimeMillis();
// if (drawCursor) {
// if ((currentTime - cursorBlinkTime) > blinkOnTime) {
// cursorBlinkTime = currentTime;
// drawCursor = false;
// return true;
// }
// } else {
// if ((currentTime - cursorBlinkTime) > blinkOffTime) {
// cursorBlinkTime = currentTime;
// drawCursor = true;
// return true;
// }
// }
// if (pressedAndNotReleased) {
// if (currentTime - pressTime >= getLongClickDuration()) {
// longClick(pressedKeyCode);
// }
// } else {
// if (pendingCommit && currentTime - releaseTime > commitTimeout) {
// commitChange();
// }
// }
// } else {
// drawCursor = false;
// }
// return ani;
// }
// public boolean animate() {
// boolean ani = super.animate();
// if (hasFocus()) {
// long currentTime = System.currentTimeMillis();
// if (drawCursor) {
// if ((currentTime - cursorBlinkTime) > blinkOnTime) {
// cursorBlinkTime = currentTime;
// drawCursor = false;
// return true;
// }
// } else {
// if ((currentTime - cursorBlinkTime) > blinkOffTime) {
// cursorBlinkTime = currentTime;
// drawCursor = true;
// return true;
// }
// }
// if (pressedAndNotReleased) {
// if (currentTime - pressTime >= getLongClickDuration()) {
// longClick(pressedKeyCode);
// }
// } else {
// if (pendingCommit && currentTime - releaseTime > commitTimeout) {
// commitChange();
// }
// }
// } else {
// drawCursor = false;
// }
// return ani;
// }

一个是Display


lwuitGraphics.setGraphics(impl.getNativeGraphics());
这两个暂时还没有仔细去研究,但是确实吃内存的所在。
还有就是要巧用System.gc();进行内存回收,这样就会尽量的减少内存溢出的情况。
9、滚动条拖拽方向与内容显示相反,component中的代码修改如下

view plaincopy to clipboardprint?
public void pointerDragged(int x, int y) {
if (isScrollable() && isSmoothScrolling()) {
int axisValue;
if (isScrollableY()) {
axisValue = y;
} else {
axisValue = x;
}
if (!dragActivated) {
dragActivated = true;
beforeLastScrollY = axisValue;
lastScrollY = axisValue;
getComponentForm().setDraggedComponent(this);
}
//save time and locations to create velocity when the
//pointer is released
long currentTime = System.currentTimeMillis();
if (currentTime != lastTime[(pLastDragged + lastTime.length + 1) % lastTime.length]) {
lastTime[pLastDragged] = System.currentTimeMillis();
lastDragged[pLastDragged] = axisValue;
pLastDragged = (++pLastDragged) % lastTime.length;
}
beforeLastScrollY = lastScrollY;
lastScrollY = axisValue;
// we drag inversly to get a feel of grabbing a physical screen
// and pulling it in the reverse direction of the drag
if (isScrollableY()) {
int scroll = getScrollY() - (beforeLastScrollY - axisValue);
if (scroll >= 0 && scroll < getPreferredH() - getHeight()) {
setScrollY(scroll);
}
} else {
int scroll = getScrollX() - (beforeLastScrollY - axisValue);
if (scroll >= 0 && scroll < getPreferredW() - getWidth()) {
setScrollX(scroll);
}
}
} else {
//try to find a scrollable element until you reach the Form
Component parent = getParent();
if (!(parent instanceof Form)) {
parent.pointerDragged(x, y);
}
}
}
public void pointerDragged(int x, int y) {
if (isScrollable() && isSmoothScrolling()) {
int axisValue;
if (isScrollableY()) {
axisValue = y;
} else {
axisValue = x;
}
if (!dragActivated) {
dragActivated = true;
beforeLastScrollY = axisValue;
lastScrollY = axisValue;
getComponentForm().setDraggedComponent(this);
}
//save time and locations to create velocity when the
//pointer is released
long currentTime = System.currentTimeMillis();
if (currentTime != lastTime[(pLastDragged + lastTime.length + 1) % lastTime.length]) {
lastTime[pLastDragged] = System.currentTimeMillis();
lastDragged[pLastDragged] = axisValue;
pLastDragged = (++pLastDragged) % lastTime.length;
}
beforeLastScrollY = lastScrollY;
lastScrollY = axisValue;
// we drag inversly to get a feel of grabbing a physical screen
// and pulling it in the reverse direction of the drag
if (isScrollableY()) {
int scroll = getScrollY() - (beforeLastScrollY - axisValue);
if (scroll >= 0 && scroll < getPreferredH() - getHeight()) {
setScrollY(scroll);
}
} else {
int scroll = getScrollX() - (beforeLastScrollY - axisValue);
if (scroll >= 0 && scroll < getPreferredW() - getWidth()) {
setScrollX(scroll);
}
}
} else {
//try to find a scrollable element until you reach the Form
Component parent = getParent();
if (!(parent instanceof Form)) {
parent.pointerDragged(x, y);
}
}
}


10、开启wtk模拟器的触摸屏功能
打开\wtklib\devices\DefaultColorPhone目录下的DefaultColorPhone.properties文件(最好先安装一个UltraEdit之类的文本编辑器)。
然后找到touch_screen选项,修改为touch_screen=true

11、设置模拟器权限,以免开发过程中弹出烦人的提示
打开wtk模拟器。
选择Edit->Preferences->Security
然后将Security domain的选项设置为maximum。

12、内存和性能监视器
Edit->Preferences->Memory Monitor
Edit->Preferences->Profiler

13、出现安装后无法打开问题
有些Nokia手机会出现安装后无法打开,原因是安装包名称包含中文导致。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lwuit/archive/2009/12/03/4930931.aspx

分享到:
评论

相关推荐

    Lwuit一些简单测试小应用程序Demo

    Lwuit一些简单测试小应用程序Demo 大家可以在真机上测试一下

    LWUIT 入门资料个人整理

    个人整理的LWUIT资料. 入门资料. 比较适合于新手学习LWUIT.基本概括了所有的资源

    LWUIT.jar LWUIT.jar

    LWUIT.jarLWUIT.jarLWUIT.jarLWUIT.jarLWUIT.jarLWUIT.jar

    最新LWUIT_1_5

    LWUIT哦,最新的包,学习学习。非常好用哦

    Lwuit入门程序测试一下Demo

    Lwuit入门程序测试一下Demo 里面需要用到LWUIT的jar包

    lwuit-blackberry上移植的版本

    Lwuit在blackberry上的移植版本,使用subversion签下来的,我把这个从lwuit-incubator中提取出来的,里面有DOC和源码,不过它把4.2-4.7版本放在一起了,应用的时候需要根据自己项目实际进行裁剪和修改。

    LWUIT_3_1英文原版.part1

    The Lightweight UI Toolkit (LWUIT) 是一个轻量级JavaME UI工具包。LWUIT类似Swing 的MVC架构, 支持多种布局(Layouts), 皮肤更换, 字体, 触摸屏, 动画效果, Rich控件, 3D集成, Painter, 模式对画框, I18N/L10N等...

    lwuit 1.2.1lwuit 最新

    The Lightweight UI Toolkit (LWUIT) 是一个轻量级JavaME UI工具包。LWUIT类似Swing 的MVC架构, 支持多种布局(Layouts), 皮肤更换, 字体, 触摸屏, 动画效果, Rich控件, 3D集成, Painter, 模式对画框, I18N/L10N等...

    lwuit1.4介绍

    根据搜索翻译出来的lwuit1.4的介绍,有兴趣的朋友可以看看

    LWUIT的最新源代码(官方的LWUIT.jar反编译)

    在网上找了很久源代码,基本上都是缺胳膊少腿的,svn上1.3版的代码还处于测试阶段...官方的只通了LWUIT.jar和Demo的下载,没有源代码,我把这个LWUIT.jar反编译了一下,把反编译过后产生的错误修改好了,已经可以用了。

    LWUIT最新源代码

    Sun发布了LWUIT(Light-Weight UI Toolkit)的源代码。项目主页访问:LWUIT。 The Lightweight UI Toolkit (LWUIT) 是一个轻量级JavaME UI工具包。LWUIT类似Swing 的MVC架构, 支持多种布局(Layouts), 皮肤更换, ...

    lwuit1.4 jar包

    lwuit1.4 jar包 lwuit1.4 jar包 lwuit1.4 jar包 lwuit1.4 jar包

    lwuit Developer_Guide

    lwuit的开发文档 Hello World for MIDP import com.sun.lwuit.Display; import com.sun.lwuit.Form; import com.sun.lwuit.Label; import com.sun.lwuit.layouts.BorderLayout; import ...

    lwuit_demo_src.rar_DEMO_J2ME lwuit de_LWUIT_lwuit demo

    lwuit demo 的源代码,基本重要的函数都在这里进行了展示

    lwuit 1.4 api文档

    lwuit 1.4 api文档,lwuit 1.4 api文档。

    lwuit.rar_J2ME lwuit_LWUIT_j2me_j2me LWU_九宫

    J2ME lwuit实现屏幕九宫图,功能十分强大

    lwuit api文档下载

    lwuit api文档下载,lwuit api文档下载

    LWUIT1.3code.rar_LWUIT

    lwuit源代码,是sun 公司为J2ME开发的一套UI,是一套经典的设计,为大型J2ME客户端的开发提供了很好的工具

    LWUIT,j2me教程

    LWUIT,j2me教程,LWUIT 简介 教程与文档 问答LWUIT是一个轻量级JavaME UI工具包。特性:类似Swing 的MVC架构,支持多种布局(Layouts),皮肤更换,字体,触摸屏,动画效果...

    lwuit最新源代码

    lwuit最新源代码,包含table和tree,最新的lwuit已经支持了

Global site tag (gtag.js) - Google Analytics