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

📄 edgedborder.java

📁 使用java application 的共享白板系统
💻 JAVA
字号:
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;

public class EdgedBorder implements Border {
	public EdgedBorder(Color edgeColor) {
		this.edgeColor = edgeColor;
	}

	// Set explicit shadow colors
	public void setShadowColors(Color lightShadow, Color darkShadow) {
		this.lightShadow = lightShadow;
		this.darkShadow = darkShadow;
	}

	// Border interface
	public Insets getBorderInsets(Component comp) {
		return new Insets(BORDER_PAD, BORDER_PAD, BORDER_PAD, BORDER_PAD);
	}

	public void paintBorder(Component comp, Graphics g, int x, int y, int width, int height) {
		Color saveColor = g.getColor();
		int totalBorder = 2 * BORDER_PAD;

		// Use the component color if a null color has been supplied
		if (edgeColor == null) {
			edgeColor = comp.getBackground();
			lightShadow = null;
			darkShadow = null;
		}

		// Determine the border colors if 
		// they have not been supplied
		if (lightShadow == null) {
			lightShadow = edgeColor.brighter();
			darkShadow = edgeColor.darker();
		}

		// Draw the colored edge on which the shadow resides
		g.setColor(edgeColor);
		g.fillRect(x, y, width, BORDER_PAD);
		g.fillRect(x, y + height - BORDER_PAD, width, BORDER_PAD);
		g.fillRect(x, y + BORDER_PAD, BORDER_PAD, height - totalBorder);
		g.fillRect(x + width - BORDER_PAD, y + BORDER_PAD, 
								BORDER_PAD, height - totalBorder);

		// Draw the shadow
		g.setColor(lightShadow);
		g.drawRect(x + OUTER_PAD + 1, y + OUTER_PAD + 1, 
					width - 2 * OUTER_PAD - 1,
					height - 2 * OUTER_PAD - 1);
		g.setColor(darkShadow);
		g.drawRect(x + OUTER_PAD, y + OUTER_PAD,
					width - 2 * OUTER_PAD - 1,
					height - 2 * OUTER_PAD - 1);

		// Restore graphics context color
		g.setColor(saveColor);

	}

	public boolean isBorderOpaque() {
		return true;
	}

	private Color edgeColor;
	private Color lightShadow;
	private Color darkShadow;
	
	// Constants
	private static final int OUTER_PAD = 2;
	private static final int BORDER_SIZE = 2;
	private static final int INNER_PAD = 2;
	private static final int BORDER_PAD = 
								OUTER_PAD + BORDER_SIZE + INNER_PAD;
}

⌨️ 快捷键说明

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