import java.awt.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class ChessBoard extends JPanel{
/* * 制作棋盘的宽高; */
public static final int BOARD_WIDTH=515;
/* * 计算棋盘表格坐标(单元格宽高相等) */
public static int [] location=new int[22];
static{ for(int i=0,WIDTH=30;i<location.length;i++,WIDTH+=22){
location[i]=WIDTH;
}
}
/** * 重写方法,绘制棋盘表格图; */
public void paintComponent(Graphics g){
super.paintComponent(g);
char ch='A';
g.setFont(new Font("宋体",Font.BOLD,12));
//画横线
for(int i=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); }
//画竖线
for(int i=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);
}
}
}
import javax.swing.*;
@SuppressWarnings("serial")
public class ChessBoard extends JPanel{
/* * 制作棋盘的宽高; */
public static final int BOARD_WIDTH=515;
/* * 计算棋盘表格坐标(单元格宽高相等) */
public static int [] location=new int[22];
static{ for(int i=0,WIDTH=30;i<location.length;i++,WIDTH+=22){
location[i]=WIDTH;
}
}
/** * 重写方法,绘制棋盘表格图; */
public void paintComponent(Graphics g){
super.paintComponent(g);
char ch='A';
g.setFont(new Font("宋体",Font.BOLD,12));
//画横线
for(int i=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); }
//画竖线
for(int i=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);
}
}
}