【Java】在J2ME下面开发触摸屏的软件-DEMO

本文介绍如何在MIDP2.0环境下启用触摸屏支持,并详细解析了触摸屏事件处理方法,包括pointerPressed、pointerReleased等,通过实例展示了如何响应触摸屏上的软键点击。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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:
        case Consts.S_MAP_VIEW:
            // 左右软键40*20的区域
            if (x < 40 && y > (screenHeight - 20)) {
                doCommandLeft();
            }
            if (x > (screenWidth - 40) && y > (screenHeight - 20)) {
                doCommandRight();
            }
            break;
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值