/*----------------------------------------------- 直線のループによる図形描画(1) ------------------------------------------------*/ import java.applet.*; import java.awt.*; public class Applet_drawLine_loop1 extends Applet { public void paint(Graphics g) { // --------- 縦の平行線 --------- int x; for ( x=100 ; x<=300 ; x=x+10 ) { g.drawLine(x, 50, x, 300); } // --------- 横の平行線 --------- int y; for ( y=400 ; y<=600 ; y=y+10 ) { g.drawLine(100, y, 300, y); } // --------- 斜めの線 --------- g.setColor(Color.blue); for ( x=400 ; x<=800 ; x=x+5) { g.drawLine(400, 50, x, 300); } // --------- 逆方向から斜めの線 --------- g.setColor(Color.red); for ( x=400 ; x<=800 ; x=x+5 ) { g.drawLine(800, 50, x, 300); } // --------- 中央から斜めの線 --------- g.setColor(Color.green); for ( x=400 ; x<=800 ; x=x+5 ) { g.drawLine(600, 550, x, 300); } } }