为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

触屏手机

2018-02-03 6页 doc 19KB 31阅读

用户头像

is_995397

暂无简介

举报
触屏手机触屏手机 使用J2ME技术实现手机触摸屏开发的方法: 首先的修改调试环境,默认情况下是不支持触摸操作的。 在WTK目录下的 \WTK\wtklib\devices\DefaultColorPhone\DefaultColorPhone.properties的 文件中的: touch_screen=false,改成true。 即支持触摸屏开发。 MIDP2.0对于触摸屏方法有三个: 1.pointerDragged(int x, int y) 触摸屏拖拽事件; 2.pointerPressed(int x, in...
触屏手机
触屏手机 使用J2ME技术实现手机触摸屏开发的: 首先的修改调试环境,默认情况下是不支持触摸操作的。 在WTK目录下的 \WTK\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)当用户按下释放触摸屏的时候会自动调用这个 方法,x,y就是当前释放的坐标。 pointerDragged(int x, int y) 触摸屏拖拽触发的事件; 先给出简单的测试代码(仅有pointerPressed(int,int)): 首先MIDlet: Java代码 import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class MyMidlet extends MIDlet { public MyMidlet() { } protected void destroyApp(boolean flag) throws MIDletStateChangeException { } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { Display.getDisplay(this).setCurrent(new TestPointCanvas()); } } import javax.microedition.lcdui.Display; import javax.microedition.midlet.MIDlet; import javax.microedition.midlet.MIDletStateChangeException; public class MyMidlet extends MIDlet { public MyMidlet() { } protected void destroyApp(boolean flag) throws MIDletStateChangeException { } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { Display.getDisplay(this).setCurrent(new TestPointCanvas()); } }再次Canvas: Java代码 import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; public class TestPointCanvas extends Canvas { private static int rx, ry; protected void paint(Graphics g) { g.setColor(255, 255, 255); g.fillRect(0, 0, 240, 320); g.setColor(0, 0, 0); g.drawString("This is a touch test!", 60, 100, 20); g.drawString("left:" + rx, 20, 260, 20); g.drawString("right:" + ry, 180, 260, 20); } protected void pointerPressed(int x, int y) { if (x < 40 && y > 240) { doCommandL(); } if (x > 200 && y > 240) { doCommandR(); } repaint(); } protected void keyPressed(int key) { if (key == -6) { doCommandL(); } if (key == -7) { doCommandR(); } repaint(); } private void doCommandL() { rx++; } private void doCommandR() { ry++; } } import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.Graphics; public class TestPointCanvas extends Canvas { private static int rx, ry; protected void paint(Graphics g) { g.setColor(255, 255, 255); g.fillRect(0, 0, 240, 320); g.setColor(0, 0, 0); g.drawString("This is a touch test!", 60, 100, 20); g.drawString("left:" + rx, 20, 260, 20); g.drawString("right:" + ry, 180, 260, 20); } protected void pointerPressed(int x, int y) { if (x < 40 && y > 240) { doCommandL(); } if (x > 200 && y > 240) { doCommandR(); } repaint(); } protected void keyPressed(int key) { if (key == -6) { doCommandL(); } if (key == -7) { doCommandR(); } repaint(); } private void doCommandL() { rx++; } private void doCommandR() { ry++; } }OK,现在很简单吧。 深入了解了解。
/
本文档为【触屏手机】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索