其实很简单,只要从一个Border类中继承,然后重写其paintBorder方法就好了。像下面的代码所产生的就是一个三面有线一面没线的边框。
class
MyBorder
extends
LineBorder
...
{
public MyBorder(Color color) ...{
super(color, 1, false);
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) ...{
Color oldColor = g.getColor();
int i;
g.setColor(lineColor);
for(i = 0; i < thickness; i++) ...{
g.drawLine(x+i, y+i, x+i, height-i-i-1);
g.drawLine(x+i, height-i-i-1, width-i-i-1, height-i-i-1);
g.drawLine(width-i-i-1, y+i, width-i-i-1, height-i-i-1);
}
g.setColor(oldColor);
}
}
public MyBorder(Color color) ...{
super(color, 1, false);
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) ...{
Color oldColor = g.getColor();
int i;
g.setColor(lineColor);
for(i = 0; i < thickness; i++) ...{
g.drawLine(x+i, y+i, x+i, height-i-i-1);
g.drawLine(x+i, height-i-i-1, width-i-i-1, height-i-i-1);
g.drawLine(width-i-i-1, y+i, width-i-i-1, height-i-i-1);
}
g.setColor(oldColor);
}
}