java2d破折号
问题描述:
我需要使用java2d制作动画选择工具的解决方案。java2d破折号
我知道的BasicStroke和Rectagnle2D API,但我制作的黑色和白色虚线
和动画this.anybody对此项工作的想法没有想法?
感谢
答
void paint(Graphics2D g) {
//define these constants yourself
float dashWidth;
float offset;
//draw solid, i.e. background
g.setColor(Color.WHITE);
g.setStroke(new BasicStroke(width, cap, join, miter, null));
g.drawLine(x1, y1, x2, y2);
//draw the pattern on top
float[] pattern = new float[] {dashWidth, dashWidth*2}
g.setColor(Color.BLACK);
g.setStroke(new BasicStroke(width, cap, join, miter, pattern, offset));
g.drawLine(x1, y1, x2, y2);
}
这适用于任何形状,所以用的drawRect取代的drawLine如果这就是你所需要的。动画,切换颜色和重绘。