PointerMotionDemo.java
资源名称:J2ME&Game.rar [点击查看]
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:
J2ME
开发平台:
Java
- import javax.microedition.midlet.*;
- import javax.microedition.lcdui.*;
- public class PointerMotionDemo extends MIDlet {
- Display display;
- PointerCanvas pc;
- boolean isPointed = false;
- public PointerMotionDemo() {
- display = Display.getDisplay(this);
- pc= new PointerCanvas();
- }
- public void startApp () {
- display.setCurrent(pc);
- }
- public void pauseApp() {
- }
- public void destroyApp (boolean unconditional) {
- pc=null;
- display=null;
- }
- class PointerCanvas extends Canvas {
- int width = this.getWidth();
- int height = this.getHeight();
- int x,y;
- boolean firsttime = true;
- public PointerCanvas() {
- System.out.println(hasPointerEvents());
- System.out.println(hasPointerMotionEvents());
- }
- protected void paint(Graphics g) {
- if(firsttime){
- g.setColor(0xFFFFFF);
- g.fillRect(0, 0, width, height);
- g.setColor(0x000000);
- firsttime = false;
- }
- if(isPointed){
- g.setColor(0x000000);
- g.drawRect(x,y,0,0);
- isPointed = false;
- }
- }
- protected void pointerPressed(int x, int y) {
- this.x = x;
- this.y = y;
- isPointed = true;
- repaint();
- }
- protected void pointerDragged(int x, int y){
- pointerPressed(x, y);
- }
- protected void pointerReleased(int x, int y){
- }
- }
- }