java2d dash Pattern
i need solution for making animated selection tool with java2d.
i know BasicStroke and Rectagnle2D AP开发者_运维百科I but i don't idea for making black and white dashes
and animated this.anybody have idea for this work ?
thanks
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);
}
This works with any shape, so replace drawLine with drawRect if that's what you need. To animate, switch colors and repaint.
精彩评论