macoo

记录收获的点点滴滴

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

1、textArea 显示文本内容,在部分手机上无法显示全部内容,每一行的最后几个字被挡住
琢磨了很久终于找了出来,解决方案如下:

 

1 TextArea txtContent = new TextArea(strContent, 12, 24);
2 //添加这一句即可
3 txtContent.setWidestChar('');

 

2、若要对文本框中的内容设置补丁:

 

1 txtContent.getStyle().setPadding(Component.RIGHT, 10);

 

内容往右10像素

3、如果list上不想要显示文字多余时的省略号

1 name.setEndsWith3Points(false);

 

4、重写Dialog要让标题与Form的样式一致

1 dialog.show(100, 100100100, true);

 

5、声音播放

1 try {
2 InputStream is = getClass().getResourceAsStream(
3 "/res/NewMailSound.wav");
4 Player player = Manager.createPlayer(is, "audio/x-wav");
5 player.start();
6 } catch (Exception e) {
7 e.printStackTrace();
8 }

 

6、使得TextField也能够在触屏手机上点击时出现输入编辑
解决方法:
在TextField源码上 加上editString();函数:

1 public void pointerReleased(int x, int y) {
2 // unlike text area the text field supports shifting the cursor with the touch screen
3   editString();
4 String text = getText();
5 int textLength = text.length();
6 int position = 0;
7 Font f = getStyle().getFont();
8 x -= getAbsoluteX();
9 for(int iter = 0 ; iter < textLength ; iter++) {
10 int width = f.substringWidth(text, 0, iter);
11 if(x > width) {
12 position = iter;
13 } else {
14 break;
15 }
16 }
17 if(position == textLength - 1) {
18 if(f.stringWidth(text) < x) {
19 position = textLength;
20 }
21 }
22 setCursorPosition(position);
23 repaint();
24 }

 

或者官方的解决方法:http://forums.java.net/jive/thread.jspa?threadID=52716 

7、震动

 

1 public void MakeVibrate() {
2 new Thread() {
3 public void run() {
4 try {
5 Display.getInstance().vibrate(2000);
6 } catch (Exception e) {
7 e.printStackTrace();
8 }
9 }
10 }.start();
11 }

 

8、导致内存激增的原因(可以用自动模拟器的内存检测器进行监测C:\WTK2.5.2\bin\prefs.exe将你要的设置勾选)
而lwuit里面的源码有两句是会导致内存一直占用,一个是TextField中的这段代码

 

 

 

1 // public boolean animate() {
2 // boolean ani = super.animate();
3 // if (hasFocus()) {
4 // long currentTime = System.currentTimeMillis();
5 // if (drawCursor) {
6 // if ((currentTime - cursorBlinkTime) > blinkOnTime) {
7 // cursorBlinkTime = currentTime;
8 // drawCursor = false;
9 // return true;
10 // }
11 // } else {
12 // if ((currentTime - cursorBlinkTime) > blinkOffTime) {
13 // cursorBlinkTime = currentTime;
14 // drawCursor = true;
15 // return true;
16 // }
17 // }
18 // if (pressedAndNotReleased) {
19 // if (currentTime - pressTime >= getLongClickDuration()) {
20 // longClick(pressedKeyCode);
21 // }
22 // } else {
23 // if (pendingCommit && currentTime - releaseTime > commitTimeout) {
24 // commitChange();
25 // }
26 // }
27 // } else {
28 // drawCursor = false;
29 // }
30 // return ani;
31 // }

 

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

1 public void pointerDragged(int x, int y) {
2 if (isScrollable() && isSmoothScrolling()) {
3 int axisValue;
4 if (isScrollableY()) {
5 axisValue = y;
6 } else {
7 axisValue = x;
8 }
9
10 if (!dragActivated) {
11 dragActivated = true;
12 beforeLastScrollY = axisValue;
13 lastScrollY = axisValue;
14 getComponentForm().setDraggedComponent(this);
15 }
16 //save time and locations to create velocity when the
17 //pointer is released
18   long currentTime = System.currentTimeMillis();
19 if (currentTime != lastTime[(pLastDragged + lastTime.length + 1) % lastTime.length]) {
20 lastTime[pLastDragged] = System.currentTimeMillis();
21 lastDragged[pLastDragged] = axisValue;
22 pLastDragged = (++pLastDragged) % lastTime.length;
23 }
24
25 beforeLastScrollY = lastScrollY;
26 lastScrollY = axisValue;
27
28 // we drag inversly to get a feel of grabbing a physical screen
29 // and pulling it in the reverse direction of the drag
30   if (isScrollableY()) {
31 int scroll = getScrollY() - (beforeLastScrollY - axisValue);
32 if (scroll >= 0 && scroll < getPreferredH() - getHeight()) {
33 setScrollY(scroll);
34 }
35 } else {
36 int scroll = getScrollX() - (beforeLastScrollY - axisValue);
37 if (scroll >= 0 && scroll < getPreferredW() - getWidth()) {
38 setScrollX(scroll);
39 }
40 }
41 } else {
42 //try to find a scrollable element until you reach the Form
43   Component parent = getParent();
44 if (!(parent instanceof Form)) {
45 parent.pointerDragged(x, y);
46 }
47 }
48 }

 

 

 

 

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

14、想要保存Sun Java (TM) Wireless Toolkit 2.5.2 for CLDC模拟器的RMS值,可以通过Preference - 存储(s)存储根目录  :(例:/disk)  来设置.

(选择你想要用的模拟器)然后到C:\Documents and Settings\Administrator\j2mewtk\2.5.2\appdb\DefaultColorPhone\filesystem\root1 建disk文件夹。
15、在S60 3th FP2版本上会出现String Index Out of Bounds Exception;原因DefaultLookAndFeel.java,在计算字符超过屏幕时出现异常。
int widest = f.charWidth('W');必须改成int widest = f.charWidth('一');

16、如果客户端创建出现cvs [server aborted]: "add" requires write access to the repository,将服务器端的CVSNT Advanced的All user are read即可.

 

以上内容转自:http://www.cnblogs.com/datong/archive/2009/07/22/1528325.html

 

 

posted on 2010-04-29 10:39  macoo  阅读(313)  评论(0编辑  收藏  举报