Line2DTest.java



/** Line2D の実験 */
import java.awt.*;
import java.awt.geom.*;
public class Line2DTest extends Canvas {

  /** コンストラクタ */
    public Line2DTest() {
        super();
        setBackground( Color.white );
        setSize( 250, 250 );
    }

  /** 描画メソッド */

    public void paint( Graphics g ) {
        Line2D.Float line1
            = new Line2D.Float( 10.0f, 10.0f, 240.0f, 240.0f );
        Line2D.Float line2
            = new Line2D.Float( 10.0f, 240.0f, 240.0f, 10.0f );
        BasicStroke bs = new BasicStroke( 6.0f,
            BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER );
        g.setColor( Color.black );
        ((Graphics2D)g).draw( line1 );
        ((Graphics2D)g).setStroke( bs );
        ((Graphics2D)g).draw( line2 );
    }

  /** 最初に呼び出されるメソッド */
    public static void main( String argv[] ) {
         Frame frame = new Frame( "Draw Line Test" );  
         Line2DTest canvas = new Line2DTest();  
         frame.add( canvas, "Center" );
         frame.pack();
         frame.show();
    }
}