19 3!!...... (+) (>) (++) (+=) for while 3.1!! 3.1.1 50 20 20 5 (20, 20) 3.1.1 (1)(Blocks1.java) public class Blocks1 extends JApplet { public void paint(graphics g){ 5 g.drawrect( 20, 20, 50, 20); g.drawrect( 90, 20, 50, 20); g.drawrect(160, 20, 50, 20); g.drawrect(230, 20, 50, 20); g.drawrect(300, 20, 50, 20); 10 3.1.1 6 10 50 20 (20, 20),
20 3!! (90, 20), (160, 20), (230, 20), (300, 20) O 50 100 150 200 250 300 350 x 50 100 y 3.1 5 3.1.2 50 20 20 5 (20, 20) 3.1.3 50 10 10 5 (20, 20) 3.1.4 50 10 10 10 (20, 20) 3.1.2 3.1.3 3.1.2 3.1.5 3.1.1
3.1!! 21 3.1.2 (2)(Blocks2.java) public class Blocks2 extends JApplet { public void paint(graphics g){ 5 int w = 50, h = 20, x = 20, y = 20, space = 20; x = x + w + space; 10 x = x + w + space; x = x + w + space; 15 x = x + w + space; 20 (variable) Java (type) 1, 12, -50 int 1.23, -10.5 float, double (declaration) ;,,... ; (int, double ) ( ) int w; double s, s1, s_x; camel case camel case = (assignment) = ; w = 50; w 50 Java
22 3!! int w = 50; Java F.3 3.1.1 (x, y) (x +, y) = (x + +, y) w space x + (w + space) 10 x( 20) w, space( 50 20) x x 90 3.1.6 3.2(a) gif a (10, 10) a (http://ushikai.com/index.htm) web 3.1.3 (1)(ImagePut.java) import javax.swing.imageicon; public class ImagePut extends JApplet { 5 ImageIcon icon; public void init(){ icon = new ImageIcon(getImage(getCodeBase(), "den1s.gif")); 10 public void paint(graphics g) { icon.painticon(this, g, 10, 10); 15 (a) (den1s.gif) (b) 3.1.3 (c) 3.1.4 3.2 applet 3.1.3 9 ImageIcon
3.1!! 23 init applet URL(Uniform Resource Locator) URL *1 getcodebase applet URL URL *2 ImageIcon painticon this this applet 3.1.7 3.2(a) gif (10, 10) 3.1.4 (2)(ImagePutBox.java) import javax.swing.imageicon; public class ImagePutBox extends JApplet { 5 ImageIcon icon; int w, h; public void init(){ icon = new ImageIcon(getImage(getCodeBase(), "den1s.gif")); 10 w = icon.geticonwidth(); h = icon.geticonheight(); public void paint(graphics g) { 15 icon.painticon(this, g, 10, 10); g.drawrect(10, 10, w, h); 3.1.8 3.2(a) gif 5 3.1.9 3.2(a) gif 5 3.1.10 50 20 20 10 (20, 20) 3.1.11 50 10 10 10 (20, 20) *1 http://www.img.cs.titech.ac.jp/ rocky/lecture/java/src/den1s.gif URL "http://www.img.cs.titech.ac.jp/ rocky/lecture/java/src/" "den1s.gif" URL "http://www.img.cs.titech.ac.jp/ rocky/lecture/java/" "./src/den1s.gif" *2 http://www.img.cs.titech.ac.jp/ rocky/lecture/java/src/imageput.html applet URL http://www.img.cs.titech.ac.jp/ rocky/lecture/java/src/
24 3!! 3.1.12 3.2(a) gif 10 3.2!! Java while for do-while for while 3.2.1 3.2.1 for 3.1.2 3.2.1 (3)(Blocks3.java) public class Blocks3 extends JApplet { public void paint(graphics g){ 5 int w = 50, h = 20, x = 20, y = 20, space = 20, i; for(i = 0; i < 5; i++){ x = x + w + space; 10 3.2.1 for for for 3 for for ( ; ; ) : for : : for false true 3.3 for for
3.2!! 25 for for(i = 0; i < 5; i++){ ; i 0 i 1 i 5 < i 5 (true) 5 (false) F.4 ++ 1 Java 0 3.2.2 for 50 20 20 5 (20, 20) 3.2.3 for 50 10 10 10 (20, 20) 3.2.4 for 3.2(a) gif 5 3.2.2 3.2.5 50 20 20 (20, 20) HTML 3.2.2 (4)(Blocks4.java) import java.awt.dimension; public class Blocks4 extends JApplet { 5 public void paint(graphics g){ int w = 50, h = 20, x = 20, y = 20, space = 20; Dimension d = getsize(); while(x + w < d.width){ 10 x = x + w + space; 15
26 3!! 3.2.3 3.2.2 html ( 200 )(blocks4-200.html) <html> <applet code="blocks4.class" width=200 height=60> </applet> </htlm> 3.2.4 3.2.2 html ( 800 )(blocks4-800.html) <html> <applet code="blocks4.class" width=800 height=60> </applet> </htlm> while 3.2.2 8 getsize 11 14 while x w d.width while while( ) false true while while 3.4 while 3.2.6 50 20 20 (20, 20) HTML 3.2.7 50 10 20 10 (20, 20) HTML 3.2.8 3.2(a) gif 3.3!! 3.3.1 50 20 20 10 5 5 (20, 20)
3.4 27 3.3.1 (5)(Blocks5.java) public class Blocks5 extends JApplet { public void paint(graphics g){ 5 int w = 50, h = 20, xs = 20, ys = 10; for(int j = 0, y = 20; j < 5; j++, y += (h + ys)){ for(int i = 0, x = 20; i < 5; i++, x += (w + xs)){ 10 for while 3.3.1 8 12 for 2 9 11 for 5 x 20 w + xs = 70 9 i, x 0, 20 Java for for i, x 9 11 9 j, y 9 11 9 i x (w + xs) x += (w + xs) x = x + (w + xs) 9 11 for 5 for y (h + ys) for 5 5 for 5 5 5 3.3.2 50 10 20 10 (20, 20) HTML 3.3.3 3.2(a) gif 3.4 3.1 3.5(a) 3.2 3.5(b) 3.3 3.2(a) gif 3.5(a) 3.6(a) 3.4 3.2(a) gif 3.5(b) 3.6(b)
28 3!! (a) (b) 3.5 (a) (b) 3.6 3.5 3.7(a) 3.6 3.7(b) 3.7 3.8(a) 3.8 3.8(b)
3.4 29 (a) (b) 3.7 (a) (b) 3.8