J2me触屏代码

  /****************
  *  触摸屏 *
  * *************/
 
 
 protected int getPointerKey(int x,int y)
 {
     int scrH=240;
     int key = -100;
 if(inRect(x,y,65,10+scrH,30,15)){
            key=49;
    }
    if(inRect(x,y,100,9+scrH,43,14)){
            key=50;///KEY_2;
    }
    else if(inRect(x,y,145,10+scrH,30,15)){
            key=51;
    }
    else if(inRect(x,y,65,30+scrH,23,23)){
            key=52;// ///4;
    }
    else if(inRect(x,y,92,26+scrH,57,26)){
            key=53;
    }
    else if(inRect(x,y,152,30+scrH,23,23)){
            key=54;//6;
    }
    else if(inRect(x,y,65,55+scrH,30,25)){
         key = 55;//KEY_7
    }
    else if(inRect(x,y,100,55+scrH,43,25)){
            key=56;///KEY_8;
    }
    else if(inRect(x,y,145,55+scrH,43,25)){
            key=57;
    }
//    else if (inRect(x,y,65,70+scrH,30,15)){
//            key=KEY_STAR;
//    }
//    else if (inRect(x,y,100,70+scrH,43,15)){
//            key=KEY_NUM0;
//    }
//    else if (inRect(x,y,145,70+scrH,43,15)){
//            key=KEY_POUND;
//    }
    else if (inRect(x,y,10,-30+scrH,40,65)){
            key=-6;
    }
    else if (inRect(x,y,190,-30+scrH,30,65)){
            key=-7;
    }
    return key;
 }

 protected boolean inRect(int ptx,int pty,int x,int y,int width,int height)
 {
     if((ptx>x)&&(ptx<x+width)&&(pty>y)&&(pty<y+height))
         return true;
     else
         return false;
 }
 
 public int anjian = 9999;
 
 
 protected void pointerPressed(int x,int y)
    {
         keyPressed(getPointerKey(x,y));
         anjian = getPointerKey(x,y);
    }
 protected void pointerReleased(int x, int y )
 {
   keyReleased(anjian);
   anjian = 9999;
//      keyReleased(getPointerKey(x,y));
 }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值