服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

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

本文简单介绍了如何使用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; 
        } 
    }

扫描关注微信公众号