import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ChessBoard extends JPanel implements MouseListener,MouseMotionListener
{
public ChessPoint point[][];
public int unitWidth,unitHeight;
int x轴长,y轴长;
int x,y;
boolean move=false;
public String 红方颜色="红色",黑方颜色="黑色";
ChessPiece 红车1,红车2,红马1,红马2,红相1,红相2,红帅,红士1,红士2,
红兵1,红兵2,红兵3,红兵4,红兵5,红炮1,红炮2;
ChessPiece 黑车1,黑车2,黑马1,黑马2,黑将,黑士1,黑士2,
黑卒1,黑卒2,黑卒3,黑卒4,黑卒5,黑象1,黑象2,黑炮1,黑炮2;
int startX,startY;
int startI,startJ;
public boolean 红方走棋=true,黑方走棋=false;
Rule rule=null;
public MakeChessManual record=null;
public ChessBoard(int w,int h,int r,int c)
{
setLayout(null);
addMouseListener(this);
addMouseMotionListener(this);
Color bc=getBackground();
unitWidth=w;
unitHeight=h;
x轴长=r;
y轴长=c;
point=new ChessPoint[r+1][c+1];
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
point[i][j]=new ChessPoint(i*unitWidth,j*unitHeight,false);
}
}
rule=new Rule(this,point);
record=new MakeChessManual(this,point) ;
红车1=new ChessPiece("车",Color.red,bc,w-4,h-4,this);
红车1.set棋子类别(红方颜色);
红车2=new ChessPiece("车",Color.red,bc,w-4,h-4,this);
红车2.set棋子类别(红方颜色);
红马1=new ChessPiece("马",Color.red,bc,w-4,h-4,this);
红马1.set棋子类别(红方颜色);
红马2=new ChessPiece("马",Color.red,bc,w-4,h-4,this);
红马2.set棋子类别(红方颜色);
红炮1=new ChessPiece("炮",Color.red,bc,w-4,h-4,this);
红炮1.set棋子类别(红方颜色);
红炮2=new ChessPiece("炮",Color.red,bc,w-4,h-4,this);
红炮2.set棋子类别(红方颜色);
红相1=new ChessPiece("相",Color.red,bc,w-4,h-4,this);
红相1.set棋子类别(红方颜色);
红相2=new ChessPiece("相",Color.red,bc,w-4,h-4,this);
红相2.set棋子类别(红方颜色);
红士1=new ChessPiece("士",Color.red,bc,w-4,h-4,this);
红士1.set棋子类别(红方颜色);
红士2=new ChessPiece("士",Color.red,bc,w-4,h-4,this);
红士2.set棋子类别(红方颜色);
红帅=new ChessPiece("帅",Color.red,bc,w-4,h-4,this);
红帅.set棋子类别(红方颜色);
红兵1=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵1.set棋子类别(红方颜色);
红兵2=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵2.set棋子类别(红方颜色);
红兵3=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵3.set棋子类别(红方颜色);
红兵4=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵4.set棋子类别(红方颜色);
红兵5=new ChessPiece("兵",Color.red,bc,w-4,h-4,this);
红兵5.set棋子类别(红方颜色);
黑将=new ChessPiece("将",Color.blue,bc,w-4,h-4,this);
黑将.set棋子类别(黑方颜色);
黑士1=new ChessPiece("士",Color.blue,bc,w-4,h-4,this);
黑士1.set棋子类别(黑方颜色);
黑士2=new ChessPiece("士",Color.blue,bc,w-4,h-4,this);
黑士2.set棋子类别(黑方颜色);
黑车1=new ChessPiece("车",Color.blue,bc,w-4,h-4,this);
黑车1.set棋子类别(黑方颜色);
黑车2=new ChessPiece("车",Color.blue,bc,w-4,h-4,this);
黑车2.set棋子类别(黑方颜色);
黑炮1=new ChessPiece("炮",Color.blue,bc,w-4,h-4,this);
黑炮1.set棋子类别(黑方颜色);
黑炮2=new ChessPiece("炮",Color.blue,bc,w-4,h-4,this);
黑炮2.set棋子类别(黑方颜色);
黑象1=new ChessPiece("象",Color.blue,bc,w-4,h-4,this);
黑象1.set棋子类别(黑方颜色);
黑象2=new ChessPiece("象",Color.blue,bc,w-4,h-4,this);
黑象2.set棋子类别(黑方颜色);
黑马1=new ChessPiece("马",Color.blue,bc,w-4,h-4,this);
黑马1.set棋子类别(黑方颜色);
黑马2=new ChessPiece("马",Color.blue,bc,w-4,h-4,this);
黑马2.set棋子类别(黑方颜色);
黑卒1=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒1.set棋子类别(黑方颜色);
黑卒2=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒2.set棋子类别(黑方颜色);
黑卒3=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒3.set棋子类别(黑方颜色);
黑卒4=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒4.set棋子类别(黑方颜色);
黑卒5=new ChessPiece("卒",Color.blue,bc,w-4,h-4,this);
黑卒5.set棋子类别(黑方颜色);
point[1][10].setPiece(红车1,this);
point[2][10].setPiece(红马1,this);
point[3][10].setPiece(红相1,this);
point[4][10].setPiece(红士1,this);
point[5][10].setPiece(红帅,this);
point[6][10].setPiece(红士2,this);
point[7][10].setPiece(红相2,this);
point[8][10].setPiece(红马2,this);
point[9][10].setPiece(红车2,this);
point[2][8].setPiece(红炮1,this);
point[8][8].setPiece(红炮2,this);
point[1][7].setPiece(红兵1,this);
point[3][7].setPiece(红兵2,this);
point[5][7].setPiece(红兵3,this);
point[7][7].setPiece(红兵4,this);
point[9][7].setPiece(红兵5,this);
point[1][1].setPiece(黑车1,this);
point[2][1].setPiece(黑马1,this);
point[3][1].setPiece(黑象1,this);
point[4][1].setPiece(黑士1,this);
point[5][1].setPiece(黑将,this);
point[6][1].setPiece(黑士2,this);
point[7][1].setPiece(黑象2,this);
point[8][1].setPiece(黑马2,this);
point[9][1].setPiece(黑车2,this);
point[2][3].setPiece(黑炮1,this);
point[8][3].setPiece(黑炮2,this);
point[1][4].setPiece(黑卒1,this);
point[3][4].setPiece(黑卒2,this);
point[5][4].setPiece(黑卒3,this);
point[7][4].setPiece(黑卒4,this);
point[9][4].setPiece(黑卒5,this);
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
for(int j=1;j<=y轴长;j++)
{
g.drawLine(point[1][j].x,point[1][j].y,point[x轴长][j].x,point[x轴长][j].y);
}
for(int i=1;i<=x轴长;i++)
{
if(i!=1&&i!=x轴长)
{
g.drawLine(point[i][1].x,point[i][1].y,point[i][y轴长-5].x,point[i][y轴长-5].y);
g.drawLine(point[i][y轴长-4].x,point[i][y轴长-4].y,point[i][y轴长].x,point[i][y轴长].y);
}
else
{
g.drawLine(point[i][1].x,point[i][1].y,point[i][y轴长].x,point[i][y轴长].y);
}
}
g.drawLine(point[4][1].x,point[4][1].y,point[6][3].x,point[6][3].y);
g.drawLine(point[6][1].x,point[6][1].y,point[4][3].x,point[4][3].y);
g.drawLine(point[4][8].x,point[4][8].y,point[6][y轴长].x,point[6][y轴长].y);
g.drawLine(point[4][y轴长].x,point[4][y轴长].y,point[6][8].x,point[6][8].y);
for(int i=1;i<=x轴长;i++)
{
g.drawString(""+i,i*unitWidth,unitHeight/2);
}
int j=1;
for(char c='A';c<='J';c++)
{
g.drawString(""+c,unitWidth/4,j*unitHeight);
j++;
}
}
public void mousePressed(MouseEvent e)
{
ChessPiece piece=null;
Rectangle rect=null;
if(e.getSource()==this)
move=false;
if(move==false)
if(e.getSource() instanceof ChessPiece)
{
piec
没有合适的资源?快使用搜索试试~ 我知道了~
java小程序源代码
共71个文件
java:71个
5星 · 超过95%的资源 需积分: 10 292 下载量 121 浏览量
2009-11-22
11:18:41
上传
评论 10
收藏 85KB RAR 举报
温馨提示
记忆测试软件、计算器、Hannoi塔、JPEG图像生成器、标准考试系统(单机版)、标准考试系统(CS网络版)、标准考试系统(BS网络版)、日历记事本、学籍管理系统、图书查询系统(BS网络版)、中国象棋打谱软件、模版游戏、挖雷游戏、网络聊天室(BS模式)、局域网络广播系统java程序源代码
资源推荐
资源详情
资源评论
收起资源包目录
15个Java小程序原代码.rar (71个子文件)
15个Java小程序原代码
chap2计算器
ComputerPad.java 12KB
NumberButton.java 320B
OperationButton.java 317B
chap15局域网络广播系统
Receive.java 3KB
BroadCastWord.java 4KB
chap12魔板游戏
SquarePoint.java 746B
PuzzleFrame.java 2KB
PuzzlePad.java 6KB
chap7标准化考试系统(BS网络版)
Server.java 4KB
ClientBS.java 3KB
ClientTestArea.java 6KB
ChoiceFile.java 3KB
ReadTestquestion.java 4KB
chap1记忆测试软件
People.java 302B
Memory.java 6KB
Record.java 2KB
RandomSetIcon.java 861B
Block.java 697B
ShowRecord.java 3KB
MemoryTestPane.java 4KB
chap13 挖雷游戏
TimeCount.java 583B
Game.java 4KB
CountMine.java 497B
Record.java 3KB
Block.java 3KB
ShowRecord.java 4KB
FindAroundMineNumber.java 2KB
FindSafeArea.java 1KB
DecideWinner.java 760B
MineSquare.java 9KB
FindAroundMineMarkNumber.java 514B
RandomSetMine.java 990B
DetermineMineMarkIsRightOrWrong.java 1002B
DetermineDigArea.java 2KB
chap4JPEG图像生成器
MakeJPEG.java 7KB
chap8日历记事本
NotePad.java 6KB
Year.java 2KB
CalendarPad.java 6KB
Month.java 2KB
chap5标准考试系统(单机版)
EnglishTest.java 695B
TestArea.java 8KB
ReadTestquestion.java 4KB
chap9学籍管理系统
ModifySituation.java 8KB
Inquest.java 4KB
StudentManager.java 3KB
Delete.java 5KB
StudentSituation.java 6KB
Student.java 1KB
chap10图书查询系统 (BS网络版)
DatabaseClient.java 4KB
DatabaseServer.java 4KB
chap11中国象棋打谱软件
ChessPiece.java 1KB
MoveStep.java 194B
Rule.java 9KB
Chess.java 5KB
MakeChessManual.java 4KB
Demon.java 6KB
ChessPoint.java 989B
ChessBoard.java 14KB
chap6标准化考试系统 (CS网络版))
Server.java 4KB
ClientTestArea.java 6KB
ChoiceFile.java 3KB
ReadTestquestion.java 4KB
Client.java 4KB
chap3Hannoi塔
Disk.java 497B
Tower.java 2KB
HannoiTower.java 13KB
TowerPoint.java 868B
chap14网络聊天室 (BS模式)
InputNameTextField.java 4KB
ChatArea.java 6KB
ClientChat.java 3KB
ChatServer.java 6KB
共 71 条
- 1
进化论之歌
- 粉丝: 12
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页