board.java

来自「connectN 网络游戏。内含server and client端源程序」· Java 代码 · 共 36 行

JAVA
36
字号
package client;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import javax.swing.JPanel;

public class Board extends JPanel {
	private static final long serialVersionUID = 1L;
	private int row;
	private int col;

	public Board(int row, int col) {
		this.row = row;
		this.col = col;
		this.setBackground(Color.white);
		setLayout(new GridLayout(row, col, 0, 0));
	}

	protected void paintComponent(Graphics g) {
		super.paintComponent(g);
		int width = getWidth();
		int height = getHeight();
		// draw Rectangle
		g.setColor(Color.black);
		g.drawRect(0, 0, width - 1, height - 1);
		// draw line
		for (int i = 0; i < row - 1; i++) {
			g.drawLine(0, height / row * (i + 1), width, height / row * (i + 1));
		}
		for (int j = 0; j < col - 1; j++) {
			g.drawLine(width / col * (j + 1), 0, width / col * (j + 1), height);
		}
	}
}

⌨️ 快捷键说明

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