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

熱點內容
yii資料庫配置文件 發布:2025-03-19 12:04:03 瀏覽:177
稅票網路配置怎麼填寫 發布:2025-03-19 12:02:39 瀏覽:473
三星的文件夾怎麼 發布:2025-03-19 12:01:07 瀏覽:818
安卓機如何生成wifi二維碼 發布:2025-03-19 12:00:22 瀏覽:833
字元串大寫php 發布:2025-03-19 11:47:02 瀏覽:955
紅白機rom反編譯 發布:2025-03-19 11:37:00 瀏覽:889
英特爾存儲盤的類型 發布:2025-03-19 11:35:36 瀏覽:920
linux修改svn 發布:2025-03-19 11:27:11 瀏覽:11
老爹起床鈴怎麼設置安卓 發布:2025-03-19 11:11:40 瀏覽:206
配置試劑的瓶子如何滅菌 發布:2025-03-19 11:07:16 瀏覽:603