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

熱點內容
固態主控演算法 發布:2025-07-02 09:38:27 瀏覽:10
計算機存儲器尺寸是多少 發布:2025-07-02 09:32:15 瀏覽:145
危化品停車場消防器材如何配置 發布:2025-07-02 09:31:37 瀏覽:813
為什麼蘋果連安卓的熱點用這么快 發布:2025-07-02 09:31:30 瀏覽:87
easyui顯示資料庫數據 發布:2025-07-02 09:30:51 瀏覽:238
櫻花計劃腳本 發布:2025-07-02 09:30:50 瀏覽:868
計算機多層存儲系統的主要組成 發布:2025-07-02 09:26:25 瀏覽:541
同等配置的聯想和戴爾哪個更好 發布:2025-07-02 09:02:33 瀏覽:125
華為如何查詢以前設置過的密碼 發布:2025-07-02 09:02:28 瀏覽:183
c語言地圖 發布:2025-07-02 09:00:14 瀏覽:490