當前位置:首頁 » 編程語言 » 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);
}
}
}
}

熱點內容
烏班圖搭建kms伺服器 發布:2025-03-19 06:36:11 瀏覽:862
android版本控制 發布:2025-03-19 06:20:59 瀏覽:181
安卓手機怎麼反色 發布:2025-03-19 06:15:19 瀏覽:822
安卓開視頻時聲音小怎麼辦 發布:2025-03-19 06:08:18 瀏覽:579
文件伺服器訪問速度慢 發布:2025-03-19 05:45:36 瀏覽:637
python的下載與安裝 發布:2025-03-19 05:41:38 瀏覽:771
安卓怎麼用手電筒檢測換屏 發布:2025-03-19 05:30:33 瀏覽:674
蘋果6怎麼設置短密碼 發布:2025-03-19 04:44:41 瀏覽:20
三人樂隊怎麼配置 發布:2025-03-19 04:34:42 瀏覽:917
趣編程入口 發布:2025-03-19 04:25:09 瀏覽:942