目标:Java web开发

接下来,Demo.java
研究了个寂寞。。。。

package cn.edu.ouc.chineseChess;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
 
/**
 * 演示棋谱类
 * 
 * @author cnlht
 */
class Demon extends JPanel implements ActionListener, Runnable {
	//ActionListener:当鼠标左键点击窗口中的按钮时触发
	public JButton replay = null, next = null, auto = null, stop = null;
	LinkedList 棋谱 = null;
	Thread 自动演示 = null;//Runable和Thread
	int index = -1;
	ChessBoard board = null;
	JTextArea text;
	JTextField 时间间隔 = null;
	int time = 1000;
	String 演示过程 = "";
	JSplitPane splitH = null, splitV = null;
 
	public Demon(ChessBoard board) {
		this.board = board;
		replay = new JButton("重新演示");
		next = new JButton("下一步");
		auto = new JButton("自动演示");
		stop = new JButton("暂停演示");
		自动演示 = new Thread(this);
		replay.addActionListener(this);
		next.addActionListener(this);
		auto.addActionListener(this);
		stop.addActionListener(this);
		text = new JTextArea();
		时间间隔 = new JTextField("1");
		setLayout(new BorderLayout());
		JScrollPane pane = new JScrollPane(text);//带有滚动条的面板
		JPanel p = new JPanel(new GridLayout(3, 2));
		p.add(next);
		p.add(replay);
		p.add(auto);
		p.add(stop);
		p.add(new JLabel("时间间隔(秒)", SwingConstants.CENTER));
		p.add(时间间隔);
		splitV = new JSplitPane(JSplitPane.VERTICAL_SPLIT, pane, p);
		splitH = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, board, splitV);
		splitV.setDividerSize(5);
		splitV.setDividerLocation(400);
		splitH.setDividerSize(5);
		splitH.setDividerLocation(460);
		add(splitH, BorderLayout.CENTER);
		validate();
	}
 
	public void set棋谱(LinkedList 棋谱) {
		this.棋谱 = 棋谱;
	}
 
	public char numberToLetter(int n) {
		char c = '\0';
		switch (n) {
		case 1:
			c = 'A';
			break;
		case 2:
			c = 'B';
			break;
		case 3:
			c = 'C';
			break;
		case 4:
			c = 'D';
			break;
		case 5:
			c = 'E';
			break;
		case 6:
			c = 'F';
			break;
		case 7:
			c = 'G';
			break;
		case 8:
			c = 'H';
			break;
		case 9:
			c = 'I';
			break;
		case 10:
			c = 'J';
			break;
		}
		return c;
	}
 
	public void actionPerformed(ActionEvent e) {//重写函数
		if (e.getSource() == next) {
			index++;
			if (index < 棋谱.size()) {
				演示一步(index);
			} else {
				演示结束("棋谱演示完毕");
			}
		}
		if (e.getSource() == replay) {
			board = new ChessBoard(45, 45, 9, 10);
			splitH.remove(board);
			splitH.setDividerSize(5);
			splitH.setDividerLocation(460);
			splitH.setLeftComponent(board);
			splitH.validate();
			index = -1;
			text.setText(null);
		}
		if (e.getSource() == auto) {
			next.setEnabled(false);
			replay.setEnabled(false);
			try {
				time = 1000 * Integer.parseInt(时间间隔.getText().trim());
			} catch (NumberFormatException ee) {
				time = 1000;
			}
 
			if (!(自动演示.isAlive())) {
				自动演示 = new Thread(this);
				board = new ChessBoard(45, 45, 9, 10);
				splitH.remove(board);
				splitH.setDividerSize(5);
				splitH.setDividerLocation(460);
				splitH.setLeftComponent(board);
				splitH.validate();
				text.setText(null);
				自动演示.start();
			}
 
		}
		if (e.getSource() == stop) {
			if (e.getActionCommand().equals("暂停演示")) {
				演示过程 = "暂停演示";
				stop.setText("继续演示");
				stop.repaint();
			}
			if (e.getActionCommand().equals("继续演示")) {
				演示过程 = "继续演示";
				自动演示.interrupt();//给线程一个受阻的信号
				stop.setText("暂停演示");
				stop.repaint();
			}
		}
	}
 
	public synchronized void run() {
		//synchronized,同步块。所有其他等待进入该同步块的线程将被阻塞,直到执行该同步块中的线程退出。
		for (index = 0; index < 棋谱.size(); index++) {
			try {
				Thread.sleep(time);
			} catch (InterruptedException e) {
			}
			while (演示过程.equals("暂停演示")) {
				try {
					wait();
				} catch (InterruptedException e) {
					notifyAll();
				}
			}
			演示一步(index);
		}
		if (index >= 棋谱.size()) {
			演示结束("棋谱演示完毕");
			next.setEnabled(true);
			replay.setEnabled(true);
		}
	}
 
	public void 演示一步(int index) {
		MoveStep step = (MoveStep) 棋谱.get(index);
		Point pStart = step.pStart;
		Point pEnd = step.pEnd;
		int startI = pStart.x;
		int startJ = pStart.y;
		int endI = pEnd.x;
		int endJ = pEnd.y;
		ChessPiece piece = (board.point)[startI][startJ].getPiece();
		if ((board.point)[endI][endJ].isPiece() == true) {
			ChessPiece pieceRemoved = (board.point)[endI][endJ].getPiece();
			(board.point)[endI][endJ].reMovePiece(pieceRemoved, board);
			board.repaint();
			(board.point)[endI][endJ].setPiece(piece, board);
			(board.point)[startI][startJ].set有棋子(false);
			board.repaint();
		} else {
			(board.point)[endI][endJ].setPiece(piece, board);
			(board.point)[startI][startJ].set有棋子(false);
 
		}
		String 棋子类别 = piece.棋子类别();
		String name = piece.getName();
		String m = "#" + 棋子类别 + name + ": " + startI + numberToLetter(startJ)
				+ " 到 " + endI + numberToLetter(endJ);
		text.append(m);
		if (piece.棋子类别().equals(board.黑方颜色))
			text.append("\n");
	}
 
	public void 演示结束(String message) {
		splitH.remove(board);
		splitH.setDividerSize(5);
		splitH.setDividerLocation(460);
		JLabel label = new JLabel(message);
		label.setFont(new Font("隶书", Font.BOLD, 40));
		label.setForeground(Color.blue);
		label.setHorizontalAlignment(SwingConstants.CENTER);
		splitH.setLeftComponent(label);
		splitH.validate();
	}
}

丫的,反正怎么都是寂寞,再寂寞一次好了。
MakeChessManual类:

package cn.edu.ouc.chineseChess;


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.LinkedList;
 
/**
 * 制作棋谱类
 * 
 * @author cnlht
 */
class MakeChessManual extends JPanel implements ActionListener {
	JTextArea text = null;//设置滚动条,编辑多行的文本
	JScrollPane scroll = null;
	ChessBoard board = null;
	ChessPoint[][] point;
	LinkedList 棋谱 = null;
	LinkedList 吃掉的棋子 = null;
	JButton buttonUndo;
	int i = 0;
 
	public MakeChessManual(ChessBoard board, ChessPoint[][] point) {
		this.board = board;
		this.point = point;
		text = new JTextArea();
		scroll = new JScrollPane(text);
		棋谱 = new LinkedList();
		吃掉的棋子 = new LinkedList();
		buttonUndo = new JButton("悔棋");
		buttonUndo.setFont(new Font("隶书", Font.PLAIN, 18));
		setLayout(new BorderLayout());
		add(scroll, BorderLayout.CENTER);
		add(buttonUndo, BorderLayout.SOUTH);
		buttonUndo.addActionListener(this);
	}
 
	public char numberToLetter(int n) {
		char c = '\0';
		switch (n) {
		case 1:
			c = 'A';
			break;
		case 2:
			c = 'B';
			break;
		case 3:
			c = 'C';
			break;
		case 4:
			c = 'D';
			break;
		case 5:
			c = 'E';
			break;
		case 6:
			c = 'F';
			break;
		case 7:
			c = 'G';
			break;
		case 8:
			c = 'H';
			break;
		case 9:
			c = 'I';
			break;
		case 10:
			c = 'J';
			break;
		}
		return c;
	}
 
	public void 记录棋谱(ChessPiece piece, int startI, int startJ, int endI,
			int endJ) {
		Point pStart = new Point(startI, startJ);
		Point pEnd = new Point(endI, endJ);
		MoveStep step = new MoveStep(pStart, pEnd);
		棋谱.add(step);
 
		String 棋子类别 = piece.棋子类别();
		String name = piece.getName();
		String m = "#" + 棋子类别 + name + ": " + startI + numberToLetter(startJ)
				+ " 到 " + endI + numberToLetter(endJ);
		text.append(m);//文本添加内容
		if (piece.棋子类别().equals(board.黑方颜色))
			text.append("\n");
	}
 
	public void 记录吃掉的棋子(Object object) {
		吃掉的棋子.add(object);
	}
 
	public LinkedList 获取棋谱() {
		return 棋谱;
	}
 
	public void actionPerformed(ActionEvent e) {//重写函数,implements ActionListener
		int position = text.getText().lastIndexOf("#");//设置文本
		if (position != -1)
			text.replaceRange("", position, text.getText().length());
		if (棋谱.size() > 0) {
			MoveStep lastStep = (MoveStep) 棋谱.getLast();
			棋谱.removeLast();
			Object qizi = 吃掉的棋子.getLast();
			吃掉的棋子.removeLast();
			String temp = qizi.toString();
			if (temp.equals("没吃棋子")) {
				int startI = lastStep.pStart.x;
				int startJ = lastStep.pStart.y;
				int endI = lastStep.pEnd.x;
				int endJ = lastStep.pEnd.y;
				ChessPiece piece = point[endI][endJ].getPiece();
 
				point[startI][startJ].setPiece(piece, board);
				(point[endI][endJ]).set有棋子(false);
 
				if (piece.棋子类别().equals(board.红方颜色)) {
					board.红方走棋 = true;
					board.黑方走棋 = false;
				}
				if (piece.棋子类别().equals(board.黑方颜色)) {
					board.黑方走棋 = true;
					board.红方走棋 = false;
				}
			} else {
				ChessPiece removedPiece = (ChessPiece) qizi;
				int startI = lastStep.pStart.x;
				int startJ = lastStep.pStart.y;
				int endI = lastStep.pEnd.x;
				int endJ = lastStep.pEnd.y;
				ChessPiece piece = point[endI][endJ].getPiece();
				point[startI][startJ].setPiece(piece, board);
				point[endI][endJ].setPiece(removedPiece, board);
				(point[endI][endJ]).set有棋子(true);
 
				if (piece.棋子类别().equals(board.红方颜色)) {
					board.红方走棋 = true;
					board.黑方走棋 = false;
				}
				if (piece.棋子类别().equals(board.黑方颜色)) {
					board.黑方走棋 = true;
					board.红方走棋 = false;
				}
			}
		}
	}
}

最后一个,MoveStep类:

package cn.edu.ouc.chineseChess;

import java.awt.Point;
 
/**
 * 走步类
 * 
 * @author cnlht
 * 
 */
class MoveStep implements java.io.Serializable {
        //java.io.Serializable,实现了Serializable接口的对象转换成byte流
        //说人话就是便于对保存到文件中的数据进行读取
	public Point pStart, pEnd;
 
	public MoveStep(Point p1, Point p2) {
		pStart = p1;
		pEnd = p2;
	}
}

8个文件都解析完了,一句话感言:No zuo no die