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

📄 animstioncanvas.java

📁 上课自己制作的一个小的J2me程序
💻 JAVA
字号:
import java.io.IOException;import javax.microedition.lcdui.Canvas;/* * To change this template, choose Tools | Templates * and open the template in the editor. */import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;/** * * @author hp */public class AnimstionCanvas extends Canvas implements Runnable{    private Image[] img;    private int direction;    public AnimstionCanvas(){        try {            direction = 0;            img = new Image[4];            img[0] = Image.createImage("/image1.png");            img[1] = Image.createImage("/image2.png");            img[2] = Image.createImage("/image3.png");            img[3] = Image.createImage("/image4.png");        } catch (IOException ex) {            ex.printStackTrace();        }           }        protected void paint(Graphics g) {        g.setColor(0xffffff);        g.fillRect(0, 0, getWidth(), getHeight());                switch(direction){            case UP:                 g.drawImage(img[0], 0, 0, 0);                 break;            case DOWN:                 g.drawImage(img[1], 0, 0, 0);                 break;            case LEFT:                 g.drawImage(img[2], 0, 0, 0);                 break;            case RIGHT:                 g.drawImage(img[3], 0, 0, 0);                 break;                                   }    }    public void run() {        //throw new UnsupportedOperationException("Not supported yet.");    }     protected void keyPressed(int keyCode){  //(this.getGameAction(keyCode))这是将keycode转换为游戏按键下的按键数字代码         direction=this.getGameAction(keyCode);         repaint();//重新去执行paint这样就可以有效果实现了         }}

⌨️ 快捷键说明

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