我有一个椭圆形,我想标记它是什么,为我的国际象棋游戏。我想用它们上的棋子名称作为字符串,但我似乎无法让它工作。在形状上画一个字符串
它甚至可以在形状上绘制字符串吗?
我的代码
public void drawPieces(Graphics2D g2d){
for(int x = 0; x < 8; x++) {
for(int y = 0; y < 8; y++) {
//reds
if(board[x][y]==24){
g2d.setColor(Color.red);
g2d.fillOval(x*80, y*80, 80, 80);
//drawstring goes here
g2d.setColor(Color.blue);
g2d.drawString("test", x*80, y*80);
}
任何建议,欢迎
编辑,万一我的格法它帮助。
public void drawGrid(Graphics2D g2d){
g2d.drawLine(0, 0, 0, 639);
g2d.drawLine(0, 0, 639, 0);
g2d.drawLine(0, 639, 639, 639);
g2d.drawLine(639, 0, 639, 639);
// draw the horizontal lines using a loop from one to 7, coordiates of each line is (0, x*80, 640, x*80) also
// draw vertical lines with coordinates of (x*80, 0, x*80, 640)
for(int i = 1; i < 8; i++) {
g2d.drawLine(0, i*80, 640, i*80);
g2d.drawLine(i*80, 0, i*80, 640);
}
//drawing the black and white squares
for (int row = 0; row < 8; row++)
for (int col = 0; col < 8; col++) {
if ((row % 2 == 0 && col % 2 == 0) || (row % 2 == 1 && col % 2 == 1) ){
g2d.setColor(black);
g2d.fillRect(row*80,col*80,80,80);
}
}
}
你能展示_exactly_你试过了吗? – kviiri
当然,我会立即进行编辑。 – Strobes
编辑,我的网格方法,以防它的帮助。 - 不,为了更好地更快地发布[SSCCE](http://sscce.org/),简短,可运行,可编译 – mKorbel