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

📄 samplecanvas.java

📁 j2me简单实例,j2me教程加源码,希望大家喜欢
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -