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

📄 mycanvas.java

📁 是基于J2ME的一个模拟手机的界面可以实现手机收发短信基于客户端和服务器端的功能
💻 JAVA
字号:
package phone.mediaSound.game.beeShot;

import java.io.IOException;
import java.util.Timer;
import java.util.Vector;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;

public class MyCanvas extends GameCanvas implements Runnable {

	private Image imageFeiJi, image;

	private Sprite sprite;

	private LayerManager manager;

	private Graphics gh;

	private Timer timer;

	private MiFeng mf;

	private BeeShotMain main;

	public static Vector vSprite;

	public static int xValue;

	public static Sprite feiji;

	MiFengMove mfm;

	int m = 0, n = 0;

	public MyCanvas(BeeShotMain dlet) {
		super(true);
		m = this.getWidth();
		n = this.getHeight();
		main = dlet;
		try {
			imageFeiJi = Image.createImage("/phone/mediaSound/game/beeShot/pictures/launch.png");
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		feiji = new Sprite(imageFeiJi);
		feiji.setFrame(0);
		manager = new LayerManager();
		gh = this.getGraphics();
		mf = new MiFeng();
		timer = new Timer();
		manager.append(feiji);

		feiji.move(this.getWidth() / 2, this.getHeight()
				- imageFeiJi.getHeight());
		vSprite = new Vector();
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j < 7; j++) {
				try {
					image = Image.createImage("/phone/mediaSound/game/beeShot/pictures/bee.png");
				} catch (IOException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
				Sprite sprite = new Sprite(image);

				vSprite.addElement(sprite);

				manager.append(sprite);

				sprite.move(j * 18 + 5, i * 7 + 30);
			}
		}
		manager.paint(gh, 0, 0);
		timer.schedule(mf, 500, 3000);

		// TODO 自动生成构造函数存根
	}

	public MyCanvas() {
		super(true);
		mfm = new MiFengMove(this);
	}

	public void paintRect() {
		gh.fillRect(0, 0, this.getWidth(), this.getHeight());
	}

	public void chongPaint() {
		manager.paint(gh, 0, 0);
		this.flushGraphics();
	}

	public void run() {

		while (true) {
			int x = 0, y = 0;
			int key = this.getKeyStates();
			if ((key & GameCanvas.LEFT_PRESSED) != 0) {
				if (feiji.getX() >= 3) {
					x = -3;
				} else {
					x = 0;
				}
			}
			if ((key & GameCanvas.RIGHT_PRESSED) != 0) {
				if (feiji.getX() <= this.getWidth() - imageFeiJi.getWidth()) {
					x = +3;//
				} else {
					x = 0;
				}
			}
			if ((key & GameCanvas.FIRE_PRESSED) != 0) {
				try {
					Image img = Image.createImage("/phone/mediaSound/game/beeShot/pictures/bom.png");
					Bom bom = new Bom(img, this);
					manager.append(bom);
					bom.move(feiji.getX() + 10, feiji.getY());

					manager.paint(gh, 0, 0);

					Thread th = new Thread(bom);
					th.start();
				} catch (IOException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
			}
			feiji.move(x, 0);
			xValue = feiji.getX();
			gh.setColor(0, 0, 0);
			gh.fillRect(0, 0, this.getWidth(), this.getHeight());
			if (vSprite.size() == 0) {
				gh.setColor(0, 255, 0);
				gh.drawString(Bom.tj.getCount() + "勝利", 40, 50, Graphics.LEFT
						| Graphics.BOTTOM);
				manager.paint(gh, 0, 0);
				this.flushGraphics();
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					// TODO 自动生成 catch 块
					e.printStackTrace();
				}
				main.show();
				break;
			}
			if (!feiji.isVisible()) {
				main.show();
				break;
			}
			manager.paint(gh, 0, 0);
			this.flushGraphics();
			try {
				Thread.sleep(10);
			} catch (InterruptedException e) {
				// TODO 自动生成 catch 块
				e.printStackTrace();
			}
		}
	}
}

⌨️ 快捷键说明

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