正在加载图片...
//WhileCounter.java 2 WhileCounter.jav /Counter-controlled repetition 3 a /Java core packages Control-variable name is counter 5 import java.awt.Graphics 6 Control-variable initial value is 1 7 /Java extension packages 8 import javax.swing.JApplet; 9 10 public class WhileCounter extends JApplet Condition tests for 11 counter's final value 12 /draw lines on applet's backgroung 13 public void paint(Graphics g 14 15 /call inherited version of method paint 16 super.paint(g Increment for counter 17 18 int counter 1; /initialization 19 20 while counter <=10){ /repetition condition 21 g.drawLine(10,250,counter *10 ) 22 ++counter /increment 23 24 }/end while structure 25 26 】//end method paint 27 圆Applet viewer:WhileCounter.class-回X 28 }/end class WhileCounter Applet Applet started. ©2006计算机系杨群 All rights lefts reserved.©2006 计算机系 杨厚群 All rights & lefts reserved. 1 // WhileCounter.java 2 // Counter-controlled repetition 3 4 // Java core packages 5 import java.awt.Graphics; 6 7 // Java extension packages 8 import javax.swing.JApplet; 9 10 public class WhileCounter 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 int counter = 1; // initialization 19 20 while ( counter <= 10 ) { // repetition condition 21 g.drawLine( 10, 10, 250, counter * 10 ); 22 ++counter; // increment 23 24 } // end while structure 25 26 } // end method paint 27 28 } // end class WhileCounter Control-variable name is counter Control-variable initial value is 1 Condition tests for counter’s final value Increment for counter WhileCounter.jav a
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有