AWT setcolor, drawstring Java AWT Abstract Window Toolkit Graphics AWT import // AWT Graphics import java.awt.graphics; // AWT Graphics paint g x y ( x, y ) drawline( x, y, x, y ) ; g.drawline( 20, 30, 200, 180 ); g.drawline( 200, 180, 20, 30 ); (20, 30) 6-1 (200, 180) drawrect( x, y,, ) ; Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-1
drawline drawrect g.drawline( 10, 10, 100, 100 ); // (10, 10 ) (100, 100 ) g.drawrect( 10, 10, 100, 100 ); // (10, 10 ) (110, 110 ) (10, 10) (100, 100) 6-2 (110, 110) drawoval( x, y,, ); 80 50 80 80 g.drawoval( 10, 10, 80, 50 ); (10, 10) 80 50 6-3 drawarc( x, y,,,, ); degree -360 360 0 g.drawarc( 20, 20, 70, 60, 135, 90 ); Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-2
(20, 20) 90 135 180 90 0 270 6-4 drawroundrect( x, y,,,, ) ; g.drawroundrect( 100, 100, 50, 40, 20, 20 ); 40 50 // 10 10 6-5 draw3drect( x, y,,, ); true false Color.gray g.setcolor( Color.gray ); g.draw3drect( 10, 10, 100, 100, true ); g.draw3drect( 50, 50, 20, 20, false ); 6-6 Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-3
fillrect( x, y,, ) ; filloval( x, y,, ); fillarc( x, y,,,, ); fillroundrect( x, y,,,, ) ; fill3drect( x, y,,, ); 6-7 setcolor setcolor public class ColoredDrawing extends Applet { g.setcolor( Color.red ); g.drawline( 0, 0, 100, 100 ); g.drawrect( 100, 0, 100, 100 ); g.setcolor( Color.green ); g.drawline( 250, 0, 350, 100 ); g.drawrect( 350, 0, 100, 100 ); // // clearrect( x, y,, ) ; Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-4
copyarea( x, y,,,, ) ; copyarea public class GraphicsTester extends Applet { g.fillrect( 10, 10, 80, 80 ); g.setcolor( Color.red ); g.filloval( 50, 50, 80, 80 ); g.copyarea( 10, 10, 120, 120, 150, 20 ); // 150, 20 6-8 drawline drawrect drawoval drawarc drawline drawline drawline while for drawline drawline drawline( x, y, x, y ) ; x x y y Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-5
y for y x public void paint (Graphics g ) { int i=1; while ( i<=100 ) { g.drawline( 100-i, i, 200-i, i ); i++; 6-9 x x public void paint (Graphics g ) { int i=1; while ( i<=100 ) { g.drawline( 100, i, 100+i, i ); i++; 6-10 x y y = ex x Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-6
public class Exponential extends Applet { int x= 1; white ( x <= 128 ) { g.drawline( x, 1, x, 128 ); g.drawline( 1, x, 128, x ); x = x * 2; 6-16 x drawrect drawroundrect public class Pyramid extends Applet { int x = 10; while ( x <= 60 ) { g.drawrect( x, x, 180 -x*2, 180 -x*2 ); x = x + 10; Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-7
6-17 drawarc x public class ArcCircle extends Applet { int x= 10; while ( x <=100 ) { g.drawoval( 10, 10, x, x ); g.drawarc( 150-x/2, 150-x/2, 100+x, 100+x, -x/4, x/2 ); x = x + 30; 11 Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-8
while while while Nesting int outer = 1; while ( outer <= 4 ) { int inner = 1; while ( inner <= 5 ) { System.out.print( "Thank you! " ); inner += 1; outer += 1; System.out.println( "" ); // // // outer inner 4 5 Thank you! 4 5 20 Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! public class LatticeDrawer extends Applet { int x, y; // y = 10; while ( y <= 70 ) { x = 10; while ( x <= 70 ) { y = y + 20; g.drawrect( x, y, 10, 10 ); x = x + 20; // // // // // // x y y while x while ( x, y ) while drawrect x Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-9
(10, 10 ) ( 30, 10 ) ( 50, 10 ) ( 70, 10 ) (10, 30 ) ( 30, 30 ) ( 50, 30 ) ( 70, 30 ) (10, 50 ) ( 30, 50 ) ( 50, 50 ) ( 70, 50 ) (10, 70 ) ( 30, 70 ) ( 50, 70 ) ( 70, 70 ) 6-1. Triplet 6-2. Pudding 6-3 Russian 1970 x 20 y 20 Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-10
while Stairs drawrect fillrect while 6-5. Arcs drawoval drawarc Copyright by Tatsuo Minohara 2004 Rev. Oct 14. Macintosh Java Primer Chapter 6-11