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

2008-08-21 17:26:46   作者:佚名   来源:豆豆网   

关键字:int WTK 技术实现 触摸屏 手机 menuItemHeight Consts screenHeight menuNum menuBarHeight

  在WTK目录下的WTK22wtklibdevicesDefaultColorPhoneDefaultColorPhone.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)类似相应触摸屏释放事件

  这里,我只是以相应左右软键及菜单事件处理为例:

  protected void pointerPressed(int x, int y) {

  switch (status) {

  case Consts.S_MENU:

  int menuWidth = 90;

  int menuItemHeight = 17;

  int menuBarHeight = 16;

  int menuNum = 10;

  if (x <menuWidth &&y >(

  screenHeight - (menuItemHeight * menuNum + menuBarHeight))) {

  int menuIndex = (y - (screenHeight - (

  menuItemHeight * menuNum + menuBarHeight))) / menuItemHeight;

  doMenuOK(menuIndex);

  }

  case Consts.S_DRAW_DIBIAO_LIST:

  case Consts.S_LOCAL_SEARCH_RESULT:

  case Consts.S_MAP_VIEW:

  // 左右软键40*20的区域

  if (x <40 &&y >(screenHeight - 20)) {

  doCommandLeft();

  }

  if (x >(screenWidth - 40) &&y >(screenHeight - 20)) {

  doCommandRight();

  }

  break;

  }

  }

 

相关阅读
泰克:追求卓越技术,应对串行数据传输的测试挑战 2008-03-24
编辑:孙树宾
本文引用地址: http://www.eeworld.com.cn/gykz/2008/0821/article_1228.html
[发表评论]
[加入收藏]
[告诉好友]
[打印本页]
[关闭窗口]
[返回顶部]
[RSS订阅]

小广播

最热点击

专栏

向农,EEWORLD副总编。被英特尔董事长贝瑞特称为“中国可与之对话的两名记者之一”

【详细】

总编随笔
汤宏琳,人皆称为“汤汤”,电子工程世界高级编辑。随着EEWORLD一起成长。

【详细】

汤汤手记
今年,是中国集成电路产业丰收的一年,相比较往年都有大幅提升。

【详细】

凯哥博客

论坛精华

精选博文