使用J2ME技术实现手机触摸屏开发的方法

来源:互联网 发布:女友是韩国人知乎 编辑:程序博客网 时间:2024/06/11 20:47

本文简单介绍了如何使用J2ME技术实现手机触摸屏开发的方法: 

  在WTK目录下的/WTK22/wtklib/devices/DefaultColorPhone/DefaultColorPhone.properties的文件中有一行touch_screen=false,把它改成true。 

  MIDP2.0对于触摸屏方法有三个: 

  1.pointerDragged(int x, int y) 触摸屏拖拽事件(暂时还没研究) 

  2.pointerPressed(int x, int y) 触摸屏按压 

  3.pointerReleased(int x, int y) 触摸屏释放 

  pointerPressed(int x, int y)当用户按下触摸屏的时候会自动调用这个方法x,y就是当前压下的坐标 

  pointerReleased(int x, int y)和pointerPressed(int x, int y)类似相应触摸屏释放事件 

  1.  protected void pointerPressed(int x, int y) {    
  2.         switch (status) {    
  3.         case Consts.S_MENU:    
  4.             int menuWidth = 90;    
  5.             int menuItemHeight = 17;    
  6.             int menuBarHeight = 16;    
  7.             int menuNum = 10;    
  8.             if (x < menuWidth && y > (   
  9. screenHeight - (menuItemHeight * menuNum + menuBarHeight))) {    
  10.                 int menuIndex = (y - (screenHeight - (   
  11. menuItemHeight * menuNum + menuBarHeight))) / menuItemHeight;    
  12.                 doMenuOK(menuIndex);    
  13.             }    
  14.         case Consts.S_DRAW_DIBIAO_LIST:    
  15.         case Consts.S_LOCAL_SEARCH_RESULT:   
  16.   
  17. case Consts.S_MAP_VIEW:    
  18.             // 左右软键40*20的区域    
  19.             if (x < 40 && y > (screenHeight - 20)) {    
  20.                 doCommandLeft();    
  21.             }   
  22.   
  23.             if (x > (screenWidth - 40) && y > (screenHeight - 20)) {    
  24.                 doCommandRight();    
  25.             }    
  26.             break;    
  27.         }    
  28.       }  

 

http://www.guaiguaier.com 乖乖儿-育儿工具资源网