borderedcanvas.java

来自「使用java application 的共享白板系统」· Java 代码 · 共 27 行

JAVA
27
字号
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

public class BorderedCanvas extends JPanel {
	// Clip the graphics context to exclude the border
	protected void excludeBorder(Graphics g, Border border, int width, int height) {
		Rectangle r = AbstractBorder.getInteriorRectangle(this, border, 
										0, 0, width, height);
		g.clipRect(r.x, r.y, r.width, r.height);		
	}

	// Override getGraphics() to clip for derived class
	public Graphics getGraphics() {
		Dimension d = getSize();

		Graphics g = super.getGraphics();

		Border border = getBorder();
		if (border != null) {
			excludeBorder(g, border, d.width, d.height);
		}

		return g;
	}	
}

⌨️ 快捷键说明

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