rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » J2ME

J2ME触摸屏

开发实现方法
 

在WTK目录下的\WTK22\wtklib\devices\DefaultColorPhone\DefaultColorPhone.properties  

《注意:一般情况下文本文档不支持,你可以用写字板,word、Eclipse或者其它编辑器打开,直接用浏览器打开也可以》 
这是你选择的DefaultColorPhone模拟器配置信息文件,可以看到

screen.width=240        (第19行,屏幕宽度)
screen.height=320      (第20行,屏幕高度)

文件中有一行touch_screen=false,把它改成true就可以在代码里写触摸屏了 。

touch_screen=true      (第39行,设置触摸屏)

MIDP2.0对于触摸屏方法有3个 
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:

顶一下
(0)
踩一下
(0)