当前位置: 代码迷 >> J2SE >> java 象棋程序的一个小疑点,希望大家帮解决一下啊多谢
  详细解决方案

java 象棋程序的一个小疑点,希望大家帮解决一下啊多谢

热度:91   发布时间:2016-04-24 01:14:50.0
java 象棋程序的一个小问题,希望大家帮解决一下啊,谢谢
public class ChessMainFrame extends JFrame implements ActionListener,MouseListener,Runnable {
private static final long serialVersionUID = 1L;
JLabel play[]=new JLabel[32];
Vector Var;
ChessRule rule;
boolean chessManClick;
int chessPlayClick=2;
Thread tmain;
static int Man,i;
ChessMainFrame(String Title){
con=this.getContentPane();
con.setLayout(null);
rule=new ChessRule();
// Var=new Vector();
jmain=new JToolBar();
text=new JLabel("欢迎使用中国象棋程序");
text.setToolTipText("信息提示");
anew=new JButton("新游戏");
anew.setToolTipText("重新开始");
exit=new JButton("退出");
exit.setToolTipText("退出程序");
repent=new JButton("退回上次棋谱");

jmain.setLayout(new GridLayout(0,4));
jmain.add(anew);
jmain.add(repent);
jmain.add(exit);
jmain.add(text);
jmain.setBounds(0,0,558,30);
con.add(jmain);
drawChessMan();
anew.addActionListener(this);
repent.addActionListener(this);
exit.addActionListener(this);
con.add(image=new JLabel(new ImageIcon("main.jpg")));
image.setBounds(0, 30,558, 620);
image.addMouseListener(this);
for(i=0;i<32;i++){
con.add(play[i]);
play[i].addMouseListener(this);
}
this.setResizable(true);
this.setTitle(Title);
this.setSize(558,670);
this.setVisible(true);
}
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);
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"+i);
}
in=new ImageIcon("黑炮.gif");
for(i=26,k=81;i<28;i++,k+=342){
play[i]=new JLabel(in);
play[i].setBounds(k,170,55,55);
play[i].setName("炮1"+i);
}
in=new ImageIcon("黑将.gif");
play[i]=new JLabel(in);
play[i].setBounds(252,56,55,55);
play[i].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");
}
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,569,55,55);
play[i].setName("卒2"+i);
  相关解决方案