?? edgedborder.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 + -