samplecanvas.java

来自「JAVAME Core technology and best practice」· Java 代码 · 共 94 行

JAVA
94
字号
package com.j2medev.chapter5;
import javax.microedition.lcdui.*;
import java.io.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class SampleCanvas extends Canvas implements Runnable
{
    Display m_Display = null;
    SampleMIDlet m_MIDlet = null;
    Image srcImage = null;
    PieceSprite sample = null;

    public SampleCanvas(Display display)
    {
        this.m_Display = display;
        try
        {
            this.srcImage = Image.createImage("/sample.png");
        }
        catch(IOException ioe)
        {
            ioe.printStackTrace();
        }
        this.sample = new PieceSprite(this.srcImage, "/sample.bin",(short)100, true);
        this.sample.setAnimation(0, true);
        this.sample.setFrame((short)0);
        new Thread(this).start();
    }
    /**
     * paint
     *
     * @param graphics Graphics
     * @todo Implement this javax.microedition.lcdui.Canvas method
     */
    protected void paint(Graphics graphics)
    {
        graphics.setColor(0xFFFFFF);
        graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
        this.sample.setNextFrame();
        this.sample.paint(graphics, this.getWidth()/2, this.getHeight()/2, 0);
    }
    /**
     * run
     */
    public void run()
    {
        while(true)
        {
            try
            {
                Thread.sleep(100);
                this.repaint();
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }
    /**
     * start
     */
    public void start()
    {
        this.m_Display.setCurrent(this);
    }
    /**
     * keyPressed
     * @param keyCode int
     */
    public void keyPressed(int keyCode)
    {
        switch(keyCode)
        {
        case Canvas.KEY_NUM5 :
            break;
        default :
            break;
        }
    }

}

⌨️ 快捷键说明

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