其實(shí)我也有用JAVA做五子棋呢~,棋盤(pán)都是用畫(huà)的,我把代碼發(fā)下,你自己試下,也不定合你一意.事件代碼我都去啦,因?yàn)槭呛?jiǎn)單的麻煩事.~!
importjava.awt.*;
importjavax.swing.*;
@SuppressWarnings(serial)
publicclassChessBoardextendsJPanel{
/*
*制作棋盤(pán)的寬高;
*/
publicstaticfinalintBOARD_WIDTH=515;
/*
*計(jì)算棋盤(pán)表格坐標(biāo)(單元格寬高相等)
*/
publicstaticint[]location=newint[22];
static{
for(inti=0,WIDTH=30;i<location.length;i++,WIDTH+=22){
location[i]=WIDTH;
}
}
publicChessBoard(intx,inty){
super(null);
this.setBounds(x,y,BOARD_WIDTH,BOARD_WIDTH);
this.setBackground(newColor(255,164,85));
}
/**
*重寫(xiě)方法,繪制棋盤(pán)表格圖;
*/
publicvoidpaintComponent(Graphicsg){
super.paintComponent(g);
charch='A';
g.setFont(newFont(宋體,Font.BOLD,12));
//畫(huà)橫線
for(inti=0,width=30+22*21;i<location.length;i++,ch++){
g.setColor(Color.black);
g.drawLine(30,location[i],width,location[i]);
g.setColor(Color.blue);
g.drawString(+ch,5,location[i]+3);
}
//畫(huà)豎線
for(inti=0,width=30+22*21;i<location.length;i++){
g.setColor(Color.black);
g.drawLine(location[i],30,location[i],width);
g.setColor(Color.blue);
g.drawString(+(i+1),location[i]-3,13);
}
}
}