2010-12-19 1 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を交換してください。アニメーション化するには、色を切り替えて再ペイントします。