📄 doggy.java
字号:
import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Canvas;import javax.microedition.lcdui.Image;public class Doggy extends Canvas implements Runnable { static final int FRAME_COUNT = 17; static final int FRAME_DELAY = 180; static final int LAST_FRAME_DELAY = 3000; static final int[] framePositions = { 0, 50, 186, 372, 558, 744, 930, 1024, 1024, 834, 651, 465, 279, 93, 0, 0, 0 }; Image doggyImages = null; int frameWidth = 0; int frameHeight = 0; int frameIndex = 0; int runLength = 0; boolean running = false; protected void showNotify() { if (doggyImages == null) { try { doggyImages = Image.createImage("/Doggy.png"); frameWidth = doggyImages.getWidth(); frameHeight = doggyImages.getHeight() / FRAME_COUNT; } catch (Exception ioe) { return; } } runLength = getWidth() - frameWidth; running = true; frameIndex = 0; new Thread(this).start(); } protected void hideNotify() { running = false; } public void run() { try { while (running) { Thread.sleep((frameIndex == FRAME_COUNT - 1) ? LAST_FRAME_DELAY : FRAME_DELAY); int lastFrameIndex = frameIndex; frameIndex = (frameIndex + 1) % FRAME_COUNT; int repaintLeft = framePositions[lastFrameIndex]; int repaintRight = framePositions[frameIndex]; if (framePositions[lastFrameIndex] > framePositions[frameIndex]) { repaintLeft = framePositions[frameIndex]; repaintRight = framePositions[lastFrameIndex]; } repaintLeft = (repaintLeft * runLength) >> 10; repaintRight = (repaintRight * runLength) >> 10; repaint(repaintLeft, 0, frameWidth + repaintRight - repaintLeft, frameHeight); } } catch (InterruptedException e) {} } public void paint(Graphics g) { g.setColor(0xFFFFFF); g.fillRect(0, 0, getWidth(), getHeight()); g.translate((framePositions[frameIndex] * runLength) >> 10, 0); g.clipRect(0, 0, frameWidth, frameHeight); g.drawImage(doggyImages, 0, -(frameIndex * frameHeight), Graphics.LEFT + Graphics.TOP); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -