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

📄 help.java

📁 一个J2ME的游戏,有源程序.是原创!适合S60的176*208的规格.
💻 JAVA
字号:
package src;

import java.io.InputStream;
import java.util.Vector;
import javax.microedition.lcdui.Font;
import java.util.Enumeration;
import javax.microedition.lcdui.Graphics;

public class Help {

	String helpStr;

	int sw;

	int sh;

	int nh;

	int ColorCounter;

	int totalLine;

	int showLine;

	int cw;

	int lineWidth;

	String[] arrStr;

	int rh;

	int inr;

	int ry;

	/**
	 * 文本导入及相关处理方法
	 */

	public Help(String file, int w, int h) {
		sw = w;
		sh = h;
		InputStream ins = getClass().getResourceAsStream(file);
		try {
			int low = ins.read();
			int high = ins.read();
			StringBuffer strBuf = new StringBuffer();
			while ((low = ins.read()) >= 0) {
				high = ins.read();
				strBuf.append((char) ((high << 8) | low));
			}
			ins.close();
			ins = null;
			helpStr = strBuf.toString();
			strBuf = null;
		} catch (Exception ex) {
			System.out.println(ex.toString());
		}
		Font font = Font.getFont(0, 1, 8);
		lineWidth = sw - 40;
		cw = font.charWidth('国') + 2;
		nh = (sh - 20) / cw;
		int strLen = helpStr.length();
		int i = 0;
		int str = 0;
		int lw = 0;
		Vector sv = new Vector();
		Vector lv = new Vector();
		while (i < strLen) {
			sv.addElement(new Integer(str)); // new
			// Integer(str)为了把str整形加入sv,//Integer是整形类
			do {
				if (helpStr.charAt(i) == '\n' || helpStr.charAt(i) == '\r') {
					if (helpStr.charAt(i + 1) == '\n'
							|| helpStr.charAt(i + 1) == '\r')
						i += 2;
					else
						i++;
					lv.addElement(new Integer(i - str - 2));
					str = i;
					sv.addElement(new Integer(str));
					lw = 0;
				}
				lw += font.charWidth(helpStr.charAt(i));
				i++;
			} while (lw < lineWidth - cw && i < strLen);
			lw = 0;
			lv.addElement(new Integer(i - str));
			str = i;
		}
		int[] lineStart;
		int[] lineLen;
		lineStart = new int[sv.size()];
		lineLen = new int[lv.size()];
		arrStr = new String[sv.size()];
		totalLine = sv.size();
		Enumeration se, le;
		se = sv.elements();
		le = lv.elements();
		int n = 0;
		while (se.hasMoreElements() && le.hasMoreElements()) {
			Integer si, li;
			si = (Integer) se.nextElement();
			li = (Integer) le.nextElement();
			lineStart[n] = si.intValue();
			lineLen[n] = li.intValue();
			arrStr[n] = helpStr.substring(lineStart[n], lineStart[n]
					+ lineLen[n]);
			n++;
		}
		inr = (sh - 20) / arrStr.length;
		if (inr <= 0)
			inr = 1;
		rh = inr * nh;
	}

	/**
	 * 文本风格画笔
	 */

	public void draw(Graphics g) {
		g.setColor(0x000000);
		g.fillRect(0, 0, sw, sh);
		int sy = 1;
		g.setColor(0xffffff);
		for (int i = 0; i < nh; i++) {
			if ((i + showLine) >= totalLine)
				break;
			g.drawString(arrStr[i + showLine], 4, sy, 20);
			sy += cw;
		}
		g.setColor(0xffffff);
		g.fillRect(sw - 10, 0, 10, sh - 20);

		g.setColor(0x000000);
		g.fillRect(0, sh - 20, sw, 20);

		g.setColor(ColorCounter, ColorCounter, 0);
		g.drawString(" 返 回 ", sw - 36, sh - 16, 0);
		if (ColorCounter <= 240) {
			ColorCounter += 15;
		} else {
			ColorCounter = 0;
		}

		if (rh < sh - 20) {
			g.setColor(0x000000);
			g.fillRect(sw - 9, ry, 9, rh);
		}
	}

	/**
	 * 文本上移键控处理方法
	 */

	public void up() {
		if (showLine > 0) {
			showLine--;
		}
		if (ry > 0) {
			ry -= inr;
		}
	}

	/**
	 * 文本下移键控处理方法
	 */

	public void down() {
		if (showLine < totalLine - nh) {
			showLine++;
		}
		if (ry + rh < sh - 20) {
			ry += inr;
			if (ry + rh > sh - 20)
				ry = sh - 20 - rh;
		}
	}
}

⌨️ 快捷键说明

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