當前位置:首頁 » 編程語言 » java畫棋盤

java畫棋盤

發布時間: 2023-08-12 20:48:49

❶ 用java寫一個國際象棋的棋盤,輸出結果要是一張 國際象棋的棋盤

import java.awt.*;
import javax.swing.*;
public class Chessboard extends JApplet {
int baseXPosition, baseYPosition;
int currentXPosition, currentYPosition;
public void init() {
baseXPosition = 40; // 棋盤的開始x位置
baseYPosition = 40; // 棋盤的開始y位置
setBackground(Color.black); // 設置背景顏色黑色
}
public void paint(Graphics g) { // 繪制棋盤
currentXPosition = baseXPosition; // currentXPosition當前的x位置
currentYPosition = baseYPosition; // currentYPosition當前的y位置
for (int row = 0; row < 8; row++) {
currentXPosition = baseXPosition + row * 40;
for (int column = 0; column < 8; column++) {
if ((column + row) % 2 == 0)
g.setColor(Color.white); // 設置棋盤格子的顏色
else
g.setColor(Color.red); // 設置棋盤格子的顏色
currentYPosition = baseXPosition + column * 40;
g.drawRect(currentXPosition,currentYPosition,40,40);//;代碼4 //在當前位置繪制棋盤的格子;每個格子的大小是40*40像
g.fillRect(currentXPosition,currentYPosition,40,40);
}
}
}
}

熱點內容
php保留小數點後兩位 發布:2025-03-19 10:47:47 瀏覽:425
c語言long是什麼意思 發布:2025-03-19 10:47:10 瀏覽:897
離散數學編程 發布:2025-03-19 10:46:23 瀏覽:454
轎車買哪個配置的 發布:2025-03-19 10:46:22 瀏覽:841
linux打包目錄 發布:2025-03-19 10:39:02 瀏覽:206
亞瑟王資料庫 發布:2025-03-19 10:33:16 瀏覽:917
吉利帝豪15款手動擋有哪些配置 發布:2025-03-19 10:25:52 瀏覽:494
菜鳥裹裹怎麼取消加密 發布:2025-03-19 10:25:06 瀏覽:785
如何根據ip地址登入伺服器 發布:2025-03-19 10:21:57 瀏覽:743
c語言中的封裝 發布:2025-03-19 10:10:54 瀏覽:117