⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chessboard.java

📁 利用JAVA的Graphic类库以及Applet实现的一个简单的国际象棋棋盘
💻 JAVA
字号:
//Chessboard.java
//<applet code = "Chessboard.class" height="400" width="400"></applet>
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位置
       String[] a = {"a","b","c","d","e","f","g","h"};
       for (int row = 0; row < 8; row++) {
          g.setColor(Color.black);
          g.drawString(Integer.toString(row + 1),30,baseYPosition +20 + row * 40);
          currentXPosition =	baseXPosition + row * 40;
          for (int column = 0; column < 8; column++) {
            if(row == 0){
               g.setColor(Color.black);
               g.drawString(a[column],baseXPosition + 20 + column * 40,30);
            }
            if ((column + row) % 2 == 0)
               g.setColor(Color.white);    //	设置棋盘格子的颜色
            else
               g.setColor(Color.red);    //	设置棋盘格子的颜色
            currentYPosition =	baseXPosition + column * 40;
            g.fillRect(currentXPosition,currentYPosition,40,40);//;代码4    //在当前位置绘制棋盘的格子;每个格子的大小是40*40像素
          } // end inner for
       } // end for
    }	// end paint
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -