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

📄 recordmanage.java

📁 这是一个Java编写的手机象棋游戏
💻 JAVA
字号:
import javax.microedition.lcdui.*;

public class RecordManage extends Form implements CommandListener,ItemCommandListener
{
	private Command		back,del,look,delAll ,rename, send;
	private ChessRecord	chessRecord=null;
	private MainSelect	mainSelect=null;
	private StringItem[]	stringItems=null;
	//为选择来源进行变量定义
	private	int[][]		chess;
	private	ServerForm	serverForm = null;
	private	Command		select = null;
	private	boolean		ifSelect = false;
	
	public RecordManage(MainSelect ms)
	{//这个构造函数为记录管理服务
		super("记录列表");
		ifSelect = false;
		mainSelect=ms;
		chessRecord=new ChessRecord();
		back=new Command("Back",Command.EXIT,1);
		del=new Command("Del",Command.ITEM,1);
		delAll=new Command("DelAll",Command.ITEM,1);
		look=new Command("Look",Command.ITEM,1);
		rename = new Command("Rename",Command.ITEM,1);
		send = new Command("Send",Command.ITEM,1);
		stringItems=getItemList();
		addCommand(back);
		setCommandListener(this);
		//System.out.println("初始化RecordManage成功");
	}
	public RecordManage(ServerForm	s ,int[][]	chess)
	{
		//这个构造函数为选择来源服务
		super("选择来源");
		ifSelect = true;
		serverForm = s;
		this.chess = chess;
		chessRecord=new ChessRecord();
		back=new Command("Back",Command.EXIT,1);
		select = new Command("Select",Command.ITEM,1);
		stringItems=getItemList();
		addCommand(back);
		setCommandListener(this);
	}
	private StringItem[]	getItemList()
	{
		String[] recordNameList=chessRecord.getRecordList();
		int n=recordNameList.length;
		StringItem[]	items=new StringItem[n];
		for(int i=0;i<n;i++)
		{
			items[i]=new StringItem(null,recordNameList[i],Item.PLAIN);
			if(!ifSelect)
			{
				items[i].setDefaultCommand(look);
				items[i].addCommand(del);
				items[i].addCommand(delAll);
				items[i].addCommand(rename);
				items[i].addCommand(send);
			}
			else
			{
				items[i].addCommand(select);
			}
			items[i].setItemCommandListener(this);
			append(items[i]);
			append("\n");
		}
		return items;
	}
	public void commandAction(Command com,Displayable dis)
	{
		if(com == back && !ifSelect)
		{
			Chess.dis.setCurrent(mainSelect);
		}
		if(com == back && ifSelect)
		{
			Chess.dis.setCurrent(serverForm);
		}
	}
	public void commandAction(Command com,Item item)
	{
		if(com == select)
		{
			int itemNumber=0;
			for(int i=0;i<stringItems.length;i++)
			{
				if(item.equals(stringItems[i]))
				{
					itemNumber=i;
					break;
				}
			}
			//System.out.println("得到的itemNumber是:"+itemNumber);
			String indexName=((StringItem)item).getText();
			//根据名字获取原始棋盘
			chess = chessRecord.getChess(indexName);
			//System.out.println("获取初始棋盘数据成功");
			//根据名字获取走步集合
			int[]	contentIds=null,chessChance=new int[4];
			int tempRecordId=0;
			contentIds=chessRecord.getChessChance();
			for(int i = contentIds.length-1;i >= 0;i--)
			{
				tempRecordId=contentIds[i];
				chessChance=chessRecord.getChanceRecord(tempRecordId);
				int m=chessChance[0];
				int n=chessChance[1];
				int y=chessChance[2];
				int x=chessChance[3];
				//System.out.println("取得的两个位置是");
				//System.out.println(m+","+n);
				//System.out.println(y+","+x);
				chess[y][x]=chess[m][n];
				chess[m][n]=32;
				//System.out.println("棋盘数据操作一次");
			}
			//System.out.println("棋盘数据操作成功");
			serverForm.setChess(chess);
			//System.out.println("RecordManage中chess.length的长度:"+chess.length);
			Chess.dis.setCurrent(serverForm);
		}
		if(com==del)
		{
			int itemNumber=0;
			for(int i=0;i<stringItems.length;i++)
			{
				if(item.equals(stringItems[i]))
				{
					itemNumber=i;
					break;
				}
			}
			//System.out.println("得到的itemNumber是:"+itemNumber);
			String indexName=((StringItem)item).getText();
			int flag=chessRecord.delRecord(indexName);
			if(flag==0)
			{
				//System.out.println("删除记录成功");
				delete(itemNumber);
				//System.out.println("删除StringItem成功");
				//显示成功
				//errorDeal.push("删除一条走棋记录成功", this);
			}
			else
			{
				//System.out.println("删除记录失败");
				//显示失败
				//errorDeal.push("RecordManage#1", "删除一条走棋记录失败", this);
				Alert alert=new Alert("Message","删除一条走棋记录失败",null,AlertType.WARNING);
				Chess.dis.setCurrent(alert, this);
			}
		}
		if(com==delAll)
		{
			int flag=chessRecord.delAllRecord();
			if(flag==0)
			{
				//System.out.println("删除记录成功");
				deleteAll();
				//System.out.println("删除StringItem成功");
				//显示成功
				//errorDeal.push("删除全部走棋记录成功", this);
			}
			else
			{
				//errorDeal.push("RecordManage#2", "删除全部走棋记录失败", this);
				Alert alert=new Alert("Message","删除全部走棋记录失败",null,AlertType.WARNING);
				Chess.dis.setCurrent(alert, this);
			}
		}
		if(com==look)
		{
			String indexName=((StringItem)item).getText();
			LookCanvas	lookCanvas=new LookCanvas(this, indexName,chessRecord);
			//System.out.println("LookCanvas初始化成功");
			Chess.dis.setCurrent(lookCanvas);
		}
		if(com == rename)
		{
			int itemNumber=0;
			for(int i=0;i<stringItems.length;i++)
			{
				if(item.equals(stringItems[i]))
				{
					itemNumber=i;
					break;
				}
			}
			//System.out.println("得到的itemNumber是:"+itemNumber);
			StringItem	tempItem = (StringItem)item;
			ChessRenameForm	crf = new ChessRenameForm(tempItem,chessRecord,this);
			Chess.dis.setCurrent(crf);
		}
		if(com == send)
		{
			Flash flash = new Flash(this);
			flash.sending();
			flash.startFlash();
			String indexName=((StringItem)item).getText();
			//根据名字获取原始棋盘
			chess = chessRecord.getChess(indexName);
			//System.out.println("获取初始棋盘数据成功");
			//根据名字获取走步集合
			int[]	contentIds=null,chessChance=new int[4];
			int tempRecordId=0, contentLength = 0;
			contentIds=chessRecord.getChessChance();
			contentLength = contentIds.length;
			int[][] reset = new int[contentLength][];
			for(int i = contentLength-1;i >= 0;i--)
			{
				tempRecordId=contentIds[i];
				chessChance=chessRecord.getChanceRecord(tempRecordId);
				reset[contentLength - 1 - i] = chessChance;
			}
			new ClientChess(this, chess, reset, flash);
		}
	}
};

⌨️ 快捷键说明

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