⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 doodlecanvas.java

📁 这是j2me的例子,可供初学者学习,里面有源代码,是我写的
💻 JAVA
字号:
/*
 * DoodleCanvas.java
 *
 * Created on 2007年3月28日, 下午2:19
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.tan.ui.draw;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author USER
 */
public class DoodleCanvas extends Canvas implements  CommandListener{
    private Command cmExit;
    private Command cmClear;
    private int startx =0,
            starty = 0,
            currentx = 0,
            currenty = 0;
    private Doodle midlet;
    private boolean clearDisplay = false;
    /** Creates a new instance of DoodleCanvas */
    public DoodleCanvas(Doodle midlet) {
        this.midlet = midlet;
        cmExit = new Command("Exit",Command.EXIT,1);
        cmClear = new Command("Clear",Command.SCREEN,1);
        addCommand(cmExit);
        addCommand(cmClear);
        setCommandListener(this);
                
    }

    protected void paint(Graphics graphics) {
        if(clearDisplay)
        {
            graphics.setColor(255,255,255);
            graphics.fillRect(0,0,getWidth(),getHeight());
            clearDisplay = false;
            
            startx = currentx = starty=currenty = 0;
            return;
        }
        graphics.setColor(0,0,0);
        graphics.drawLine(startx,starty,currentx,currenty);
        startx = currentx;
        starty = currenty;
    }

    public void commandAction(Command command, Displayable displayable) {
        if(command == cmExit)
            midlet.exitMIDlet();
        else if (command == cmClear)
        {
            clearDisplay = true;
            repaint();
        }
        
        
    }
    
    
    protected void pointerPressed(int x,int y)
    {
        startx = x;
        starty = y;
    }
    
    protected void pointerDragged(int x,int y)
    {
        currentx = x;
        currenty = y;
        repaint();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -