我有一個橢圓形,我想標記它是什麼,爲我的國際象棋遊戲。我想用它們上的棋子名稱作爲字符串,但我似乎無法讓它工作。在形狀上畫一個字符串
它甚至可以在形狀上繪製字符串嗎?
我的代碼
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