`

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

阅读更多

转载:http://www.cnblogs.com/datong/archive/2009/07/22/1528325.html


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中的这段代码

  // 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中的代码修改如下

 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手机会出现安装后无法打开,原因是安装包名称包含中文导致。

 




 

分享到:
评论
1 楼 superliu8 2010-04-14  
以后的手机发展趋势 是触屏么?

相关推荐

    lwuit-incubator-专为blackberry移植的版本

    lwuit-incubator,含专为blackberry移植的版本,在\lwuit-incubator\trunk\awandi\bb中,里面有DOC和源码,不过它把4.2-4.7版本放在一起了,应用的时候需要根据自己项目实际进行裁剪和修改。

    lwuit-blackberry上移植的版本

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

    Lwuit-九宫格源码

    J2me使用Lwuit实现的九宫格图像用户界面。

    lwuit-1.4 源代码

    j2me 中轻量级框架,提供一套类似于swing 的J2me UI框架

    LWUIT1.2-src

    SUN公司在2009-07-15发布了最新版J2ME平台的UI库:LWUIT1.2,添加了一些新的内容,升级了资源封装和主题编辑软件,改正了很多BUG,此资源为源代码,希望对大家有所帮助!

    LWUIT1-2-1学习文档(中文版).pdf

    J2ME的LWUIT框架,很不错的一本书。

    LWUIT.jar LWUIT.jar

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

    LWUIT 入门资料个人整理

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

    最新LWUIT_1_5

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

    Lwuit入门程序测试一下Demo

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

    LWUIT最新源代码

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

    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等...

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

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

    lwuit1.4介绍

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

    JAVA ME富客户端开发-LWUIT开发文档

    LWUIT是一个轻量级用户界面程序开发包工具,专门争对JAVA ME界面开发难而设计,SUN公司于2008年5月将其免费

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

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

    lwuit1.4 jar包

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

    J2me 轻量级UI控件-lwuit1.2.1

    LWUIT是属于sun为J2ME提供的一轻量级UI组件,拥有绚丽的动态效果。在我看来还是过于臃肿了,整个jar包接近400K,更不要说加上主题资源文件了。

    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 ...

Global site tag (gtag.js) - Google Analytics