开发者

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 ?

java2d dash Pattern

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜