课外天地 李树青学习天地JavaME移动开发课件 → 程序代码——带有背景保留功能的拖拽直线


  共有15906人关注过本帖树形打印复制链接

主题:程序代码——带有背景保留功能的拖拽直线

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1949 积分:26803 威望:0 精华:34 注册:2003/12/30 16:34:32
程序代码——带有背景保留功能的拖拽直线  发帖心情 Post By:2008/10/8 22:52:21 [只看该作者]

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.midlet.MIDlet;

public class Exec extends MIDlet {
        private Display display;

        public Exec() {
                display = Display.getDisplay(this);
        }

        public void startApp() {
                display.setCurrent(new DrawPanel());
        }

        public void pauseApp() {
        }

        public void destroyApp(boolean unconditional) {
        }
}

class DrawPanel extends Canvas {
        int startX = 0;
        int startY = 0;
        int endX = 0;
        int endY = 0;
        Image image = Image.createImage(getWidth(), getHeight());

        protected void paint(Graphics g) {
                g.drawImage(image, 0, 0, 0);
                g.setColor(0,0,0);
                g.drawLine(startX, startY, endX, endY);
        }

        protected void pointerPressed(int x, int y) {
                startX = x;
                startY = y;
        }

        protected void pointerReleased(int x, int y) {
                endX = x;
                endY = y;              
                Graphics gOfImage = image.getGraphics();
                gOfImage.drawLine(startX, startY, endX, endY);
                repaint();
        }

        protected void pointerDragged(int x, int y) {
                endX = x;
                endY = y;
                repaint();
        }
}

[此贴子已经被作者于2010-12-12 18:35:24编辑过]

 回到顶部