//注册棋子移动监听 for (int i=0;i<32;i++){ con.add(play[i]);
play[i].addMouseListener(this);
}
//添加棋盘标签
con.add(image = new JLabel(new ImageIcon(\image.setBounds(0,30,558,620); image.addMouseListener(this);
//注册窗体关闭监听 this.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent we){ System.exit(0);
}
}
);
//窗体居中
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height){ frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width){ frameSize.width = screenSize.width;
}
21
this.setLocation((screenSize.width
-
frameSize.width)
/
2
280 ,(screenSize.height - frameSize.height ) / 2 - 350); } /**
** 添加棋子方法 */
public void drawChessMan(){ //流程控制 int i,k; //图标 Icon in;
//黑色棋子 //车
in = new ImageIcon(\黑车.GIF\ for (i=0,k=24;i<2;i++,k+=456){
play[i] = new JLabel(in); play[i].setBounds(k,56,55,55); play[i].setName(\车1\
}
//马
in = new ImageIcon(\黑马.GIF\ for (i=4,k=81;i<6;i++,k+=342){ play[i] = new JLabel(in);
play[i].setBounds(k,56,55,55);
-
22
}
play[i].setName(\马1\
//相
in = new ImageIcon(\黑象.GIF\for (i=8,k=138;i<10;i++,k+=228){ play[i] = new JLabel(in); play[i].setBounds(k,56,55,55); play[i].setName(\象1\
} //士
in = new ImageIcon(\黑士.GIF\for (i=12,k=195;i<14;i++,k+=114){ play[i] = new JLabel(in); play[i].setBounds(k,56,55,55); play[i].setName(\士1\
} //卒
in = new ImageIcon(\黑卒.GIF\for (i=16,k=24;i<21;i++,k+=114){ play[i] = new JLabel(in); play[i].setBounds(k,227,55,55); play[i].setName(\卒1\
} //炮
in = new ImageIcon(\黑炮.GIF\for (i=26,k=81;i<28;i++,k+=342){
23
play[i] = new JLabel(in); play[i].setBounds(k,170,55,55); play[i].setName(\炮1\
}
//将
in = new ImageIcon(\黑将.GIF\play[30] = new JLabel(in); play[30].setBounds(252,56,55,55); play[30].setName(\将1\
//红色棋子 //车
in = new ImageIcon(\红车.GIF\for (i=2,k=24;i<4;i++,k+=456){ play[i] = new JLabel(in); play[i].setBounds(k,569,55,55); play[i].setName(\车2\
} //马
in = new ImageIcon(\红马.GIF\for (i=6,k=81;i<8;i++,k+=342){ play[i] = new JLabel(in); play[i].setBounds(k,569,55,55); play[i].setName(\马2\} //相
24
in = new ImageIcon(\红象.GIF\
for (i=10,k=138;i<12;i++,k+=228){ play[i] = new JLabel(in); play[i].setBounds(k,569,55,55); play[i].setName(\象2\
} //士
in = new ImageIcon(\红士.GIF\for (i=14,k=195;i<16;i++,k+=114){ play[i] = new JLabel(in); play[i].setBounds(k,569,55,55); play[i].setName(\士2\} //兵
in = new ImageIcon(\红卒.GIF\for (i=21,k=24;i<26;i++,k+=114){ play[i] = new JLabel(in); play[i].setBounds(k,398,55,55); play[i].setName(\卒2\} //炮
in = new ImageIcon(\红炮.GIF\for (i=28,k=81;i<30;i++,k+=342){ play[i] = new JLabel(in); play[i].setBounds(k,455,55,55); play[i].setName(\炮2\}
25
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库中国象棋人人对战(5)在线全文阅读。
相关推荐: