新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > JAVA > 正文:使用J2ME技术实现手机触摸屏开发的方法

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

新客网 XKER.COM 2007-08-20 来源: dxaw 收藏本文

本文简单介绍了如何使用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)类似相应触摸屏释放事件

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

 

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; 
        } 
    }
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
阅读排行
随机推荐
实用信息推荐