PointerMotionDemo.java
上传用户:gyyuli
上传日期:2013-07-09
资源大小:3050k
文件大小:2k
源码类别:

J2ME

开发平台:

Java

  1. import javax.microedition.midlet.*;
  2. import javax.microedition.lcdui.*;
  3. public class PointerMotionDemo extends MIDlet {
  4.     Display display;
  5.     PointerCanvas pc;
  6.     boolean isPointed = false;
  7.     public PointerMotionDemo() {
  8.         display = Display.getDisplay(this);
  9.         pc= new PointerCanvas();
  10.     }
  11.     public void startApp () {
  12.         display.setCurrent(pc);
  13.     }
  14.     public void pauseApp() {
  15.     }
  16.     public void destroyApp (boolean unconditional) {
  17.         pc=null;
  18.         display=null;
  19.     }
  20.     class PointerCanvas extends Canvas {
  21.         int width = this.getWidth();
  22.         int height = this.getHeight();
  23.         int  x,y;
  24.         boolean firsttime = true;
  25.         public PointerCanvas() {
  26.             System.out.println(hasPointerEvents()); 
  27.             System.out.println(hasPointerMotionEvents());
  28.         }
  29.         protected void paint(Graphics g) {
  30.             if(firsttime){
  31.             g.setColor(0xFFFFFF);
  32.             g.fillRect(0, 0, width, height);
  33.             g.setColor(0x000000);
  34.             firsttime = false;
  35.             }
  36.            if(isPointed){
  37.            g.setColor(0x000000);
  38.            g.drawRect(x,y,0,0);
  39.            isPointed = false;
  40.            }
  41.         }
  42.         protected void pointerPressed(int x, int y) {
  43.             this.x = x;
  44.             this.y = y;
  45.             isPointed = true;
  46.             repaint();
  47.         }
  48.         protected void pointerDragged(int x, int y){
  49.             pointerPressed(x, y);
  50.         }
  51.         protected void pointerReleased(int x, int y){
  52.         
  53.         }
  54.         
  55.     }
  56.    
  57.      
  58. }