2010-12-19 109 views
0

我需要使用java2d製作動畫選擇工具的解決方案。java2d破折號

我知道的BasicStroke和Rectagnle2D API,但我製作的黑色和白色虛線

和動畫this.anybody對此項工作的想法沒有想法?

alt text

感謝

回答

0
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如果這就是你所需要的。動畫,切換顏色和重繪。