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

📄 mainselect.java

📁 这是一个Java编写的手机象棋游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;
import java.io.*;
import javax.microedition.rms.*;
import java.util.*;

public class MainSelect extends Form implements CommandListener,ItemCommandListener, Runnable
{
	//公共变量
	private Command		exit=null,enter=null;
	private int			isMainSelect = 0;
	//主菜单变量
	private StringItem	serverStringItem, clientStringItem, viewerStringItem, helpStringItem, aboutStringItem, assistStringItem;
	private	Form		telentForm, helpForm;
	private	ChoiceGroup	telentSaveChoice, telentDepthChoice, telentSoundChoice;
	//辅助功能变量
	private StringItem	recordStringItem,  phaseStringItem, setupStringItem, receiveStringItem, musicStringItem;
	private Flash		helpFlash = null;
	//帮助部分变量
	private StringItem	baseItem, errorItem, function, key, telentStringItem;
	private Form		helpContentForm;
	private String		helpFile = null;
	//系统设置变量
	private StringItem	bgItem, chessItem, riverItem, timeItem, myItem, yourItem, fontItem, selectedItem,selectItem;
	private TextField	sleepText, numberText;
	//备份还原部分变量
	private StringItem	backupStringItem, revertStringItem, clearStringItem;
	private String		savePath = null;
	//备份部分
	private List		backupList = null;
	//线程变量
	private boolean		isHelp = false;
	private MainSelect	mainSelect = null;

	public MainSelect(MainSelect ms, String s)
	{//环境设置
		super(s);
		isMainSelect = 1;
		mainSelect = ms;
		exit=new Command("退出",Command.EXIT,1);
		enter=new Command("调色",Command.OK,1);
		addCommand(exit);
		setCommandListener(this);
		bgItem = new StringItem(null,"背景",Item.PLAIN);
		chessItem = new StringItem(null,"棋盘",Item.PLAIN);
		riverItem = new StringItem(null,"楚河汉界",Item.PLAIN);
		timeItem = new StringItem(null,"计时器",Item.PLAIN);
		myItem = new StringItem(null,"我方棋子",Item.PLAIN);
		yourItem = new StringItem(null,"对方棋子",Item.PLAIN);
		fontItem = new StringItem(null,"字体",Item.PLAIN);
		selectedItem = new StringItem(null,"选中的棋子",Item.PLAIN);
		selectItem = new StringItem(null,"选择框",Item.PLAIN);
		//它的上面没有附加命令,初始数据来源于记录,并作为参数传递给调色板
		Setup set = new Setup();
		SetupRecord record = new SetupRecord();
		set = record.getUserSetup();
		int tempSleepTime = set.getSleepTime();
		String sleepTimeString = new Integer(tempSleepTime).toString();
		sleepText = new TextField("设置每次扫描棋盘的休眠时间(100-1000)", sleepTimeString, 3, TextField.NUMERIC);
		numberText = new TextField("每按键一次RGB值的变化量(1-20)", new Integer(5).toString(), 3, TextField.NUMERIC);
		bgItem.setDefaultCommand(enter);
		bgItem.setItemCommandListener(this);
		chessItem.setDefaultCommand(enter);
		chessItem.setItemCommandListener(this);
		riverItem.setDefaultCommand(enter);
		riverItem.setItemCommandListener(this);
		timeItem.setDefaultCommand(enter);
		timeItem.setItemCommandListener(this);
		myItem.setDefaultCommand(enter);
		myItem.setItemCommandListener(this);
		yourItem.setDefaultCommand(enter);
		yourItem.setItemCommandListener(this);
		fontItem.setDefaultCommand(enter);
		fontItem.setItemCommandListener(this);
		selectedItem.setDefaultCommand(enter);
		selectedItem.setItemCommandListener(this);
		selectItem.setDefaultCommand(enter);
		selectItem.setItemCommandListener(this);
		append(numberText);
		append("\n");
		append(sleepText);
		append("\n");
		append(bgItem);
		append("\n");
		append(chessItem);
		append("\n");
		append(riverItem);
		append("\n");
		append(timeItem);
		append("\n");
		append(myItem);
		append("\n");
		append(yourItem);
		append("\n");
		append(fontItem);
		append("\n");
		append(selectedItem);
		append("\n");
		append(selectItem);
	}
	public MainSelect(MainSelect ms)
	{//辅助功能
		super("辅助功能");
		isMainSelect = 2;
		mainSelect = ms;
		exit=new Command("Exit",Command.EXIT,1);
		enter=new Command("Enter",Command.OK,1);
		addCommand(exit);
		setCommandListener(this);
		recordStringItem=new StringItem(null,"记录管理",Item.PLAIN);
		phaseStringItem=new StringItem(null,"残局管理",Item.PLAIN);
		setupStringItem = new StringItem(null,"个性风格",Item.PLAIN);
		receiveStringItem = new StringItem(null,"数据共享",Item.PLAIN);
		musicStringItem= new StringItem(null,"背景音乐",Item.PLAIN);
		recordStringItem.setDefaultCommand(enter);
		recordStringItem.setItemCommandListener(this);
		phaseStringItem.setDefaultCommand(enter);
		phaseStringItem.setItemCommandListener(this);
		setupStringItem.setDefaultCommand(enter);
		setupStringItem.setItemCommandListener(this);
		receiveStringItem.setDefaultCommand(enter);
		receiveStringItem.setItemCommandListener(this);
		musicStringItem.setDefaultCommand(enter);
		musicStringItem.setItemCommandListener(this);
		append(recordStringItem);
		append("\n");
		append(phaseStringItem);
		append("\n");
		append(setupStringItem);
		append("\n");
		append(receiveStringItem);
		append("\n");
		append(musicStringItem);
	}
	public MainSelect(MainSelect ms, int i)
	{//系统帮助
		super("系统帮助");
		mainSelect = ms;
		isMainSelect = 3;
		//*********初始化命令
		exit=new Command("Exit",Command.EXIT,1);
		enter=new Command("Enter",Command.OK,1);
		addCommand(exit);
		setCommandListener(this);
		telentStringItem=new StringItem(null,"机器陪练",Item.PLAIN);
		baseItem=new StringItem(null,"象棋基础",Item.PLAIN);
		key=new StringItem(null,"快捷键列表",Item.PLAIN);
		function=new StringItem(null,"功能介绍",Item.PLAIN);
		errorItem=new StringItem(null,"错误处理",Item.PLAIN);
		telentStringItem.setDefaultCommand(enter);
		telentStringItem.setItemCommandListener(this);
		baseItem.setDefaultCommand(enter);
		baseItem.setItemCommandListener(this);
		key.setDefaultCommand(enter);
		key.setItemCommandListener(this);
		function.setDefaultCommand(enter);
		function.setItemCommandListener(this);
		errorItem.setDefaultCommand(enter);
		errorItem.setItemCommandListener(this);
		append(baseItem);
		append("\n");
		append(errorItem);
		append("\n");
		append(key);
		append("\n");
		append(function);
		append("\n");
		append(telentStringItem);
	}
	public MainSelect(MainSelect ms, boolean b)//无用参数
	{//数据备份还原
		super("备份还原");
		mainSelect = ms;
		isMainSelect = 4;
		//*********初始化命令
		exit=new Command("Exit",Command.EXIT,1);
		enter=new Command("Enter",Command.OK,1);
		addCommand(exit);
		setCommandListener(this);
		backupStringItem = new StringItem(null,"数据备份",Item.PLAIN);
		revertStringItem = new StringItem(null,"数据还原",Item.PLAIN);
		clearStringItem = new StringItem(null,"清除记录",Item.PLAIN);
		backupStringItem.setDefaultCommand(enter);
		backupStringItem.setItemCommandListener(this);
		clearStringItem.setDefaultCommand(enter);
		clearStringItem.setItemCommandListener(this);
		revertStringItem.setDefaultCommand(enter);
		revertStringItem.setItemCommandListener(this);
		append(backupStringItem);
		append("\n");
		append(revertStringItem);
		append("\n");
		append(clearStringItem);
	}
	public MainSelect()
	{//主菜单
		super("主菜单");
		isMainSelect = 0;
		//*********初始化命令
		exit=new Command("Exit",Command.EXIT,1);
		enter=new Command("Enter",Command.OK,1);
		addCommand(exit);
		setCommandListener(this);
		//*********初始化StringItem
		serverStringItem=new StringItem(null,"摆擂",Item.PLAIN);
		clientStringItem=new StringItem(null,"打擂",Item.PLAIN);
		viewerStringItem=new StringItem(null,"看擂",Item.PLAIN);
		helpStringItem = new StringItem(null,"帮助系统",Item.PLAIN);
		assistStringItem = new StringItem(null,"辅助功能",Item.PLAIN);
		aboutStringItem = new StringItem(null,"备份还原",Item.PLAIN);
		serverStringItem.setDefaultCommand(enter);
		serverStringItem.setItemCommandListener(this);
		clientStringItem.setDefaultCommand(enter);
		clientStringItem.setItemCommandListener(this);
		viewerStringItem.setDefaultCommand(enter);
		viewerStringItem.setItemCommandListener(this);
		helpStringItem.setDefaultCommand(enter);
		helpStringItem.setItemCommandListener(this);
		assistStringItem.setDefaultCommand(enter);
		assistStringItem.setItemCommandListener(this);
		aboutStringItem.setDefaultCommand(enter);
		aboutStringItem.setItemCommandListener(this);
		//************将StringItem添加到Form
		append(serverStringItem);
		append("\n");
		append(clientStringItem);
		append("\n");
		append(viewerStringItem);
		append("\n");
		append(assistStringItem);
		append("\n");
		append(aboutStringItem);
		append("\n");
		append(helpStringItem);
	}

	public void commandAction(Command com,Displayable dis)
	{
		//System.out.println("按下命令键");
		if(com == exit && dis == this && isMainSelect == 0)
			Chess.quitApp();
		if(com == exit && dis == this && (isMainSelect == 2 || isMainSelect == 1 || isMainSelect == 3 || isMainSelect == 4))
			Chess.dis.setCurrent(mainSelect);
		if(com == exit && dis == telentForm)
			Chess.dis.setCurrent(this);
		if(com == exit && dis.equals(backupList))
		{
			//System.out.println("按下exit键,退出");
			Chess.dis.setCurrent(this);
		}
		if(com == enter && dis == telentForm)
		{
			//System.out.println("开始获取选择项目的序列号");
			int	saveIndex = telentSaveChoice.getSelectedIndex();
			int depthIndex = telentDepthChoice.getSelectedIndex();
			int soundIndex = telentSoundChoice.getSelectedIndex();
			//System.out.println("获取选择项目的序列号成功");
			ChessCanvas	chessCanvas = new ChessCanvas(this, saveIndex, depthIndex, soundIndex);
			//System.out.println("构造ChessCanvas类成功");
			Chess.dis.setCurrent(chessCanvas);
			telentForm = null;
		}
		if(com == enter && dis.equals(backupList))
		{
			//System.out.println("按下enter键,开始备份");
			isHelp = false;
			new Thread(this).start();
		}
		if(com == exit && dis.equals(helpContentForm))
		{
			Chess.dis.setCurrent(this);
			helpContentForm = null;
		}
	}
	public void commandAction(Command com,Item item)
	{
		if(isMainSelect == 1)
		{
			int sleepTime = Integer.parseInt(sleepText.getString());
			if(sleepTime < 100 || sleepTime > 1000)
			{
				Alert alert=new Alert("Message","必须在100到1000之间",null,AlertType.WARNING);
				Chess.dis.setCurrent(alert, this);
				return;
			}
			int	rgb = Integer.parseInt(numberText.getString());
			if(rgb < 1 || rgb > 20)
			{
				Alert alert=new Alert("Message","必须在1到20之间",null,AlertType.WARNING);
				Chess.dis.setCurrent(alert, this);
				return;
			}
			//调色板部分
			if(item.equals(bgItem))
			{
				SetupCanvas setupCanvas = new SetupCanvas(this, 0, sleepTime, rgb);
				Chess.dis.setCurrent(setupCanvas);
			}
			if(item.equals(chessItem))
			{
				SetupCanvas setupCanvas = new SetupCanvas(this, 1, sleepTime, rgb);
				Chess.dis.setCurrent(setupCanvas);
			}
			if(item.equals(riverItem))
			{
				SetupCanvas setupCanvas = new SetupCanvas(this, 2, sleepTime, rgb);
				Chess.dis.setCurrent(setupCanvas);
			}
			if(item.equals(timeItem))
			{
				SetupCanvas setupCanvas = new SetupCanvas(this, 3, sleepTime, rgb);
				Chess.dis.setCurrent(setupCanvas);
			}
			if(item.equals(myItem))
			{
				SetupCanvas setupCanvas = new SetupCanvas(this, 4, sleepTime, rgb);
				Chess.dis.setCurrent(setupCanvas);
			}
			if(item.equals(yourItem))
			{
				SetupCanvas setupCanvas = new SetupCanvas(this, 5, sleepTime, rgb);
				Chess.dis.setCurrent(setupCanvas);
			}
				if(item.equals(fontItem))
			{

⌨️ 快捷键说明

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