正在加载图片...
12 I ForCounter.java ForCounter.java 11 Counter-controlled repetition with the for structure 3 /Java core packages Control-variable name is counter Line 20 5 import java.awt.Graphics int counter =1; Control-variable initial value is 1 7 /Java extension packages import javax.swing.JApplet; Line 20 9 Condition tests for counter <=10; 10 public class ForCounter extends JApplet counter's final value 11 12 /draw lines on applet' background Line 20 13 public void paint(Graphics g Increment for countercote 14 15 /call inherited version of method paint 16 super.paint(g ) 17 18 /Initialization, repetition condition and inctementing 19 /are all inclyded in the for structure headet. 20 for int counter =1;counter <=10;counter) 21 g.drawLine(10,10,250,counter 10 ) 22 3 }/end method paint 2 25 }//end class ForCounter 图Applet viewer:Forounter.cdas-▣X Applet Applet started ©2006计算机系杨厚群 All rights lefts reserved. ©2006 计算机系 杨厚群 All rights & lefts reserved. 1 // ForCounter.java 2 // Counter-controlled repetition with the for structure 3 4 // Java core packages 5 import java.awt.Graphics; 6 7 // Java extension packages 8 import javax.swing.JApplet; 9 10 public class ForCounter extends JApplet { 11 12 // draw lines on applet’s background 13 public void paint( Graphics g ) 14 { 15 // call inherited version of method paint 16 super.paint( g ); 17 18 // Initialization, repetition condition and incrementing 19 // are all included in the for structure header. 20 for ( int counter = 1; counter <= 10; counter++ ) 21 g.drawLine( 10, 10, 250, counter * 10 ); 22 23 } // end method paint 24 25 } // end class ForCounter Control-variable name is counter Control-variable initial value is 1 Condition tests for counter’s final value Increment for counter ForCounter.java Line 20 int counter = 1; Line 20 counter <= 10; Line 20 counter++;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有