在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;
}
}