r2.dvi

Similar documents
r14.dvi

r14.dvi

r3.dvi

r4.dvi

r8.dvi

r5.dvi

やさしいJavaプログラミング -Great Ideas for Java Programming サンプルPDF

r3.dvi

Thread

I HTML HashMap (i) (ii) :.java import java.net.*; import java.io.*; import java.util.hashmap; public class SimpleStopWatch { public static voi

untitled

Safari AppletViewer Web HTML Netscape Web Web 15-1 Applet Web Applet init Web paint Web start Web HTML stop destroy update init Web paint start Web up

I. (i) Java? (A). 2Apples (B). Vitamin-C (C). Peach21 (D). Pine_Apple (ii) Java? (A). Java (B). Java (C). Java (D). JavaScript Java JavaScript Java (i

Local variable x y i paint public class Sample extends Applet { public void paint( Graphics gc ) { int x, y;... int i=10 ; while ( i < 100 ) {... i +=

< F2D834F838C A815B A CC>

< F2D B838A835882CC8CF68EAE2E6A7464>

r4.dvi

II Java :30 12:00 I. I IV II. III. IV. ( a d) V. : this==null, T == N A ActionListener C class D actionperformed G getsource I implements K

< F2D82518CC282CC D2E6A7464>

ソフトウェア開発方法論2

アプレットの作成

6 p.1 6 Java GUI GUI paintcomponent GUI mouseclicked, keypressed, actionperformed mouseclicked paintcomponent thread, 1 GUI 6.0.2, mutlithread C

Java演習(4) -- 変数と型 --

< F2D92DE82E8914B82CC977088D32E6A7464>

2 static final int DO NOTHING ON CLOSE static final int HIDE ON CLOSE static final int DISPOSE ON CLOSE static final int EXIT ON CLOSE void setvisible

GUIプログラムⅣ

IE6 2 BMI chapter1 Java 6 chapter2 Java 7 chapter3 for if 8 chapter4 : BMI 9 chapter5 Java GUI 10 chapter6 11 chapter7 BMI 12 chap

< F2D82B682E182F182AF82F12E6A7464>

Java演習(9) -- クラスとメソッド --

< F2D F B834E2E6A7464>

r2.dvi

r6.dvi

< F2D E E6A7464>

< F2D8EA CE909482CC92EA82852E6A7464>

問題1 以下に示すプログラムは、次の処理をするプログラムである

< F2D825282CC947B909482CC A815B83682E6A>

I java A


Microsoft PowerPoint - prog10.ppt

LMNtal LMNtal LMNtal JAVA JAVA JAVA LMNtal LMNtal LMNtal

10K pdf

< F2D BCA82CC978E89BA82CC8EC08CB12E6A7464>

問1

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperforme

< F2D82518E9F8AD CC95BD8D7388DA93AE2E6A7464>

表示の更新もそういた作業のひとつに当たる スレッドの使用アニメーション アニメーションやシミュレーションなどは画面の更新が一定のタイミングで行われていく この連続した画面の更新をスレッドを利用して行う しかし paint() メソッドを直接呼び出して表示を更新することはできない その理由

< F2D89BA8EE882C E6A7464>

< F2D A838B838D96402E6A7464>

Microsoft PowerPoint - prog10.ppt

text_13.dvi

< F2D82518E9F8AD CC834F CC8CFC82AB82C68D4C>

シミュレーションの簡単な例 GUI 無しのシミュレーションを作る GUI を作る パラメタを設定するデモンストレーションをする 2 オブジェクト指向プログラミング特論

Java言語 第1回

GUIプログラムⅤ

Programming-C-9.key

5 p Point int Java p Point Point p; p = new Point(); Point instance, p Point int 2 Point Point p = new Point(); p.x = 1; p.y = 2;

< F2D A839382CC906A2E6A7464>

2 1 Web Java Android Java 1.2 6) Java Java 7) 6) Java Java (Swing, JavaFX) (JDBC) 7) OS 1.3 Java Java

Object MenuComponent MenuBar MenuItem Menu CheckboxMenuItem

:30 12:00 I. I V II. III. IV. ( a d) V. VI : A ActionListener aa addactionlistener AE ActionEvent K KeyListener ak addkeyliste

新・明解Java入門

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperformed


問題1 以下に示すプログラムは、次の処理をするプログラムである

Chapter 20. [ ] ; [ ] = new [ ] ; Color colors [ ] = new Color[ 20 ]; // 20 Button operations [ ] = new Button[ 10 ]; // 10 colors[ 3 ] = new Color( 1

< F2D B825082CC96E291E82E6A7464>

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

Microsoft PowerPoint prog1_doc2x.pptx

Java言語 第1回

Chapter JDK KeyListener keypressed(keyevent e ) keyreleased(keyevent e ) keytyped(keyevent e ) MouseListener mouseclicked(mouseeven

Java言語 第1回

( ) p.1 x y y = ( x ) 1 γ γ = filtergamma.java import java.applet.*; public class filtergamma extends Applet{ Image img; Image new_img; publi

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperformed

55 7 Java C Java TCP/IP TCP/IP TCP TCP_RO.java import java.net.*; import java.io.*; public class TCP_RO { public static void main(string[] a

任意の加算プログラム

Java学習教材

Microsoft Word 年度情報コミュニケーション実験II(Ver0.9)c.docx

Java演習(2) -- 簡単なプログラム --

<4D F736F F F696E74202D AC C8899E D834F E >

IT プロジェクト

I. java.awt.rectangle java.lang.math random Java TM API java.awt Rectangle Rectangle (x,y)... public int x Rectangle X public int y Rectangle Y public

I 4 p.2 4 GUI java.awt.event.* import /* 1 */ import mouseclicked MouseListener implement /* 2 */ init addmouselistener(this) this /* 3 */ this mousec

:30 12:00 I. I VII II. III. IV. ( a d) V. VI : this==null, T == N A ActionListener A addactionlistener C class D actionperforme

Java (7) Lesson = (1) 1 m 3 /s m 2 5 m 2 4 m 2 1 m 3 m 1 m 0.5 m 3 /ms 0.3 m 3 /ms 0.6 m 3 /ms 1 1 3

I. (i) Foo public (A). javac Foo.java java Foo.class (C). javac Foo java Foo (ii)? (B). javac Foo.java java Foo (D). javac Foo java Foo.class (A). Jav

Applet java.lang.object java.awt.component java.awt.container java.awt.panel java.applet.applet

vol.30.}...`.X...b.h

ガイダンス

: : : TSTank 2

2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q B

(Eclipse\202\305\212w\202\324Java2\215\374.pdf)

Java (9) 1 Lesson Java System.out.println() 1 Java API 1 Java Java 1

ALG ppt

2

Microsoft PowerPoint prog1_doc2.pptx

Java 3 p.2 3 Java : boolean Graphics draw3drect fill3drect C int C OK while (1) int boolean switch case C Calendar java.util.calendar A

untitled

Java 2 p.2 2 Java Hello0.class JVM Hello0 java > java Hello0.class Hello World! javac Java JVM java JVM : Java > javac 2> Q Foo.java Java : Q 2.

ただし 無作為にスレッドを複数実行すると 結果不正やデッドロックが起きる可能性がある 複数のスレッド ( マルチスレッド ) を安全に実行する ( スレッドセーフにする ) ためには 同期処理を用いるこ とが必要になる 同期処理は 予約語 synchronized で行うことができる ここでは sy

ガイダンス

Transcription:

2002 2 2003.1.29 1 2.1-2.3 (1) (2) 2.4-2.6 (1)OO (2)OO / 2.7-2.10 (1)UML (2) Java 3.1-3.3 (1) (2)GoF (3)WebSphere (4) 3.4-3.5 3.6-3.9 Java (?) 2/12( ) 20:00 2 (2 ) 3 Java (?)1 java.awt.frame Frame 1

import java.awt.*; public class XXX extends Frame { public XXX() { //... // ( )... main() public static import java.awt.*; public class XXX extends Frame { public XXX() { setsize(, ); // //... // ( )... public static void main(string[] args) { (new XXX()).setVisible(true); java XXX main() XXX ( ) setvisible()? main() main() System exit()? Quit ( ) import java.awt.*; import java.awt.event.*; public class XXX extends Frame { public XXX() { setsize(, ); // //... addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent evt) { System.exit(0); ); // ( )... public static void main(string[] args) { (new XXX()).setVisible(true); 2

WindowListner WindowAdapter API 4 4.1 import java.awt.*; import java.awt.event.*; import java.applet.*; public class R10Sample2 extends Frame { Image offimage; Graphics offgraphics; boolean go = true; double time = System.currentTimeMillis()*0.001; Animation[] a = new Animation[20]; int count = 0; public static void main(string[] args) { R10Sample2 app = new R10Sample2(); app.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); app.setsize(400, 300); app.setvisible(true); app.start(); main() a 2 ( ) public R10Sample2() { a[count++] = new MovingCircle(Color.red, 100, 100, -30, 40, 15); //a[count++] = new MovingJack(new Color(80, 120, 180), 10, 10, 80, 30, 30); //a[count++] = new LightOnOffJack(new Color(40, 120, 80), // 10, 30, 20, 20, 30, Color.red); //a[count++] = new MovingSnowman(new Color(60, 100, 80), // 110, 30, 30, 20, 30, Color.red, 1.2); //a[count++] = new WavingSnowman(new Color(120, 240, 80), // 150, 70, 40, 20, 30, Color.red, 1.2); //a[count++] = new LongNeckSnowman(new Color(150, 80, 80), // 110, 70, 40, -15, 30, Color.red, 1.2); //a[count++] = new RotateSnowman(new Color(110, 180, 120), 3

// 110, 110, -10, -15, 30, Color.red, 1.2); / public void start() { go = true; new Thread(new Runnable() { public void run() { while(go) { try { Thread.sleep(50); catch(exception ex) { double dt = System.currentTimeMillis()*0.001 - time; for(int i = 0; i < count; ++i) a[i].addtime(dt); time += dt; repaint(); ).start(); public void stop() { go = false; public void update(graphics g) { int w = getsize().width, h = getsize().height; if(offimage == null) { offimage = createimage(w, h); offgraphics = offimage.getgraphics(); offgraphics.setcolor(getbackground()); offgraphics.fillrect(0, 0, w, h); paint(offgraphics); g.drawimage(offimage, 0, 0, this); public void paint(graphics g) { for(int i = 0; i < count; ++i) a[i].draw(g); Animation interface Animation { public void draw(graphics g); public void addtime(double dt); static class MovingCircle implements Animation { Color cl; double gx, gy, vx, vy, rad; public MovingCircle(Color cl1, double x, double y, double vx1, double vy1, double rad1) { cl = cl1; gx = x; gy = y; vx = vx1; vy = vy1; rad = rad1; g.setcolor(cl); g.filloval((int)(gx-rad),(int)(gy-rad),(int)(rad*2),(int)(rad*2)); 4

gx += vx * dt; gy += vy * dt; if (gx<0.0 && vx < 0.0) { vx = -vx; if (gx>400.0 && vx > 0.0) { vx = -vx; if (gy<0.0 && vy < 0.0) { vy = -vy; if (gy>300.0 && vy > 0.0) { vy = -vy; MovingCircle paint super(...) paint() super.paint(...) paint() static class MovingJack extends MovingCircle { Color eyecolor, mouthcolor; public MovingJack(Color c, double x, double y, double vx1, double vy1, double rad1) { super(c, x, y, vx1, vy1, rad1); eyecolor = mouthcolor = c.brighter(); int u = (int)rad/4; super.draw(g); g.setcolor(eyecolor); g.fillpolygon(new int[]{(int)gx-3*u, (int)gx-2*u, (int)gx-u, new int[]{(int)gy-u, (int)gy-2*u, (int)gy-u, 3); g.fillpolygon(new int[]{(int)gx+3*u, (int)gx+2*u, (int)gx+u, new int[]{(int)gy-u, (int)gy-2*u, (int)gy-u, 3); g.setcolor(mouthcolor); g.fillpolygon(new int[]{(int)gx-u, (int)gx, (int)gx+u, new int[]{(int)gy+u, (int)gy+2*u, (int)gy+u, 3); MovingJack addtime() ( ) draw() eyecolor draw() MovingJack eyecolor static class LightOnOffJack extends MovingJack { double atime = 0.0; Color lightoncolor; public LightOnOffJack(Color c, double x, double y, double vx, double vy, double rad1, Color c1) { super(c, x, y, vx, vy, rad1); lightoncolor = c1; 5

atime += dt; super.addtime(dt); if((int)atime % 2 == 0) eyecolor = cl.brighter(); else eyecolor = lightoncolor; super.draw(g); LightOnOffJack dx dy ( ) static class MovingSnowman extends LightOnOffJack { double ratio, dx = 0, dy = 0; public MovingSnowman(Color c, double x, double y, double vx1, double vy1, double rad1, Color c1, double r) { super(c, x, y, vx1, vy1, rad1, c1); ratio = r; dy = rad*2; g.setcolor(cl); g.filloval((int)(gx+dx-rad*ratio), (int)(gy+dy-rad*ratio), (int)(rad*ratio*2), (int)(rad*ratio*2)); super.draw(g); MovingSnowman dy sin static class WavingSnowman extends MovingSnowman { public WavingSnowman(Color c, double x, double y, double vx1, double vy1, double rad1, Color c1, double r) { super(c, x, y, vx1, vy1, rad1, c1, r); super.addtime(dt); dy = rad*2 - (ratio-1)*rad*(1+math.sin(20*atime)); MovingSnowman dy dy super.draw() dy dy static class LongNeckSnowman extends MovingSnowman { public LongNeckSnowman(Color c, double x, double y, double vx1, double vy1, double rad1, Color c1, double r) { super(c, x, y, vx1, vy1, rad1, c1, r); 6

int len = (int)(rad*(atime%1)); g.setcolor(cl); g.fillrect((int)(gx-0.3*rad),(int)gy,(int)(0.6*rad),(int)rad*2+len); dy += len; super.draw(g); dy -= len; MovingSnowman? static class RotateSnowman extends MovingSnowman { public RotateSnowman(Color c, double x, double y, double vx1, double vy1, double rad1, Color c1, double r) { super(c, x, y, vx1, vy1, rad1, c1, r); super.addtime(dt); dx = rad*2*math.cos(atime); dy = rad*2*math.sin(atime); /u1a/kuno/work/r10sample2.java (?) 4.2 ( )?? N M M N M N M N ( ) import java.awt.*; import java.awt.event.*; import java.applet.*; public class R10Sample3 extends Frame { Image offimage; Graphics offgraphics; boolean go = true; double time = System.currentTimeMillis()*0.001; Animation[] a = new Animation[20]; 7

int count = 0; public static void main(string[] args) { R10Sample3 app = new R10Sample3(); app.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); app.setsize(400, 300); app.setvisible(true); app.start(); public R10Sample3() { a[count++] = new FlyingMove(new Circle(Color.red, 100, 100, 15), -30, 40); //a[count++] = new CircleMove(new Circle(Color.blue, 120, 100, 10), 30, 5); //a[count++] = new CircleMove(new Triangle(Color.green, // 100, 100, 140, 100, 80, 120), 40, 2); //a[count++] = new ChgColor(new Circle(Color.red, 100, 140, 20), // new Color[]{Color.pink, Color.cyan, Color.black, 0.5); //AnimGroup g1 = new AnimGroup(160, 100); //g1.add(new Circle(new Color(200, 155, 120), 0, 0, 40)); //g1.add(new Triangle(Color.blue, -30, 0, -10, 0, -20, -10)); //g1.add(new Triangle(Color.blue, 30, 0, 10, 0, 20, -10)); //g1.add(new Triangle(Color.blue, -10, 10, 10, 10, 0, 20)); //a[count++] = new FlyingMove(g1, 45, 35); //AnimGroup g2 = new AnimGroup(160, 100); //g2.add(new Circle(new Color(200, 155, 120), 0, 0, 40)); //g2.add(new ChgColor(new Triangle(Color.blue, -30, 0, -10, 0, -20, -10), // new Color[]{Color.red, Color.white, 0.7)); //g2.add(new CircleMove(new Triangle(Color.blue, 30, 0, 10, 0, 20, -10), // 3.0, 5.0)); //g2.add(new Triangle(Color.blue, -10, 10, 10, 10, 0, 20)); //a[count++] = new FlyingMove(g2, 25, 45); public void start() { go = true; new Thread(new Runnable() { public void run() { while(go) { try { Thread.sleep(50); catch(exception ex) { double dt = System.currentTimeMillis()*0.001 - time; for(int i = 0; i < count; ++i) a[i].addtime(dt); time += dt; repaint(); ).start(); 8

public void stop() { go = false; public void update(graphics g) { int w = getsize().width, h = getsize().height; if(offimage == null) { offimage = createimage(w, h); offgraphics = offimage.getgraphics(); offgraphics.setcolor(getbackground()); offgraphics.fillrect(0, 0, w, h); paint(offgraphics); g.drawimage(offimage, 0, 0, this); public void paint(graphics g) { for(int i = 0; i < count; ++i) a[i].draw(g); Animation interface Animation { public void draw(graphics g); public void addtime(double dt); public void moveto(double x, double y); public double getx(); public double gety(); public void setcolor(color c); public Color getcolor(); static class Circle implements Animation { Color cl; double gx, gy, rad; public Circle(Color c, double x, double y, double r) { cl = c; gx = x; gy = y; rad = r; g.setcolor(cl); g.filloval((int)(gx-rad),(int)(gy-rad),(int)(rad*2),(int)(rad*2)); public void moveto(double x, double y) { gx = x; gy = y; public double getx() { return gx; public double gety() { return gy; public void setcolor(color c) { cl = c; public Color getcolor() { return cl; Animation ( ) 1 gx gy FlyingMove 9

static class FlyingMove implements Animation { Animation anim; double gx, gy, vx, vy; public FlyingMove(Animation a, double vx1, double vy1) { anim = a; gx = a.getx(); gy = a.gety(); vx = vx1; vy = vy1; anim.draw(g); anim.addtime(dt); gx += vx * dt; gy += vy * dt; if (gx<0.0 && vx < 0.0) { vx = -vx; if (gx>400.0 && vx > 0.0) { vx = -vx; if (gy<0.0 && vy < 0.0) { vy = -vy; if (gy>300.0 && vy > 0.0) { vy = -vy; anim.moveto(gx, gy); public void moveto(double x, double y) { gx = x; gy = y; public double getx() { return gx; public double gety() { return gy; public void setcolor(color c) { anim.setcolor(c); public Color getcolor() { return anim.getcolor(); Circle static class CircleMove implements Animation { Animation anim; double gx, gy, rad, vtheta, theta = 0; public CircleMove(Animation a, double r, double vt) { anim = a; gx = a.getx(); gy = a.gety(); rad = r; vtheta = vt; anim.moveto(gx+rad*math.cos(theta), gy+rad*math.sin(theta)); anim.draw(g); anim.addtime(dt); theta += vtheta * dt; public void moveto(double x, double y) { gx = x; gy = y; public double getx() { return gx; public double gety() { return gy; public void setcolor(color c) { anim.setcolor(c); public Color getcolor() { return anim.getcolor(); ( ) static class Triangle implements Animation { Color cl; double gx, gy, dx0, dy0, dx1, dy1, dx2, dy2; public Triangle(Color c, double x0, double y0, double x1, double y1, 10

double x2, double y2) { cl = c; gx = (x0+x1+x2)/3; gy = (y0+y1+y2)/3; dx0 = x0-gx; dx1 = x1-gx; dx2 = x2-gx; dy0 = y0-gy; dy1 = y1-gy; dy2 = y2-gy; int[] x = new int[]{(int)(gx+dx0),(int)(gx+dx1),(int)(gx+dx2); int[] y = new int[]{(int)(gy+dy0),(int)(gy+dy1),(int)(gy+dy2); g.setcolor(cl); g.fillpolygon(x, y, 3); public void moveto(double x, double y) { gx = x; gy = y; public double getx() { return gx; public double gety() { return gy; public void setcolor(color c) { cl = c; public Color getcolor() { return cl; static class ChgColor implements Animation { Animation anim; Color[] colors; double time = 0, period; public ChgColor(Animation a, Color[] c, double p) { anim = a; colors = c; period = p; if(c.length == 0) throw new RuntimeException("empty color array"); anim.draw(g); anim.addtime(dt); time += dt; anim.setcolor(colors[(int)(time/period) % colors.length]); public void moveto(double x, double y) { anim.moveto(x, y); public double getx() { return anim.getx(); public double gety() { return anim.gety(); public void setcolor(color c) { public Color getcolor() { return anim.getcolor();? static class AnimGroup implements Animation { Animation[] a = new Animation[20]; int count = 0; Color cl = Color.black; double gx, gy; public AnimGroup(double x, double y) { gx = x; gy = y; public void add(animation anim) { 11

if(count+1 < a.length) a[count++] = anim; for(int i = 0; i < count; ++i) { double x = a[i].getx(), y = a[i].gety(); a[i].moveto(x+gx, y+gy); a[i].draw(g); a[i].moveto(x, y); for(int i = 0; i < count; ++i) a[i].addtime(dt); public void moveto(double x, double y) { gx = x; gy = y; public double getx() { return gx; public double gety() { return gy; public void setcolor(color c) { cl = c; public Color getcolor() { return cl; 3 2 /u1a/kuno/work/r10sample3.java 4.3 +? 1 draw() ( ) ( ) ; abstract ( ) (abstract method) ( abstract ) import java.awt.*; import java.awt.event.*; import java.applet.*; public class R10Sample4 extends Frame { Image offimage; 12

Graphics offgraphics; boolean go = true; double time = System.currentTimeMillis()*0.001; Animation[] a = new Animation[20]; int count = 0; public static void main(string[] args) { R10Sample4 app = new R10Sample4(); app.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { System.exit(0); ); app.setsize(400, 300); app.setvisible(true); app.start(); public R10Sample4() { a[count++] = new FlyingMove(new Circle(Color.red, 100, 100, 15), -30, 40); a[count++] = new CircleMove(new Circle(Color.blue, 120, 100, 10), 30, 5); a[count++] = new CircleMove(new Triangle(Color.green, 100, 100, 140, 100, 80, 120), 40, 2); a[count++] = new ChgColor(new Circle(Color.red, 100, 140, 20), new Color[]{Color.pink, Color.cyan, Color.black, 0.5); AnimGroup g1 = new AnimGroup(160, 100); g1.add(new Circle(new Color(200, 155, 120), 0, 0, 40)); g1.add(new Triangle(Color.blue, -30, 0, -10, 0, -20, -10)); g1.add(new Triangle(Color.blue, 30, 0, 10, 0, 20, -10)); g1.add(new Triangle(Color.blue, -10, 10, 10, 10, 0, 20)); a[count++] = new FlyingMove(g1, 45, 35); AnimGroup g2 = new AnimGroup(160, 100); g2.add(new Circle(new Color(200, 155, 120), 0, 0, 40)); g2.add(new ChgColor(new Triangle(Color.blue, -30, 0, -10, 0, -20, -10), new Color[]{Color.red, Color.white, 0.7)); g2.add(new CircleMove(new Triangle(Color.blue, 30, 0, 10, 0, 20, -10), 3.0, 5.0)); g2.add(new Triangle(Color.blue, -10, 10, 10, 10, 0, 20)); a[count++] = new FlyingMove(g2, 25, 45); public void start() { go = true; new Thread(new Runnable() { public void run() { while(go) { try { Thread.sleep(50); catch(exception ex) { double dt = System.currentTimeMillis()*0.001 - time; for(int i = 0; i < count; ++i) a[i].addtime(dt); time += dt; repaint(); ).start(); 13

public void stop() { go = false; public void update(graphics g) { int w = getsize().width, h = getsize().height; if(offimage == null) { offimage = createimage(w, h); offgraphics = offimage.getgraphics(); offgraphics.setcolor(getbackground()); offgraphics.fillrect(0, 0, w, h); paint(offgraphics); g.drawimage(offimage, 0, 0, this); public void paint(graphics g) { for(int i = 0; i < count; ++i) a[i].draw(g); interface Animation { public void draw(graphics g); public void addtime(double dt); public void moveto(double x, double y); public double getx(); public double gety(); public void setcolor(color c); public Color getcolor(); Animation draw() abstract static abstract class Figure implements Animation { Color cl; double gx, gy; public Figure(Color c, double x, double y) { cl = c; gx = x; gy = y; public void moveto(double x, double y) { gx = x; gy = y; public double getx() { return gx; public double gety() { return gy; public void setcolor(color c) { cl = c; public Color getcolor() { return cl; Figure static class Circle extends Figure { double rad; public Circle(Color c, double x, double y, double r) { super(c, x, y); rad = r; g.setcolor(cl); g.filloval((int)(gx-rad),(int)(gy-rad),(int)(rad*2),(int)(rad*2)); 14

static class Triangle extends Figure { double dx0, dy0, dx1, dy1, dx2, dy2; public Triangle(Color c, double x0, double y0, double x1, double y1, double x2, double y2) { super(c, (x0+x1+x2)/3, (y0+y1+y2)/3); dx0 = x0-gx; dx1 = x1-gx; dx2 = x2-gx; dy0 = y0-gy; dy1 = y1-gy; dy2 = y2-gy; int[] x = new int[]{(int)(gx+dx0),(int)(gx+dx1),(int)(gx+dx2); int[] y = new int[]{(int)(gy+dy0),(int)(gy+dy1),(int)(gy+dy2); g.setcolor(cl); g.fillpolygon(x, y, 3); 1 Container static abstract class Container extends Figure { Animation anim; public Container(Animation a) { super(a.getcolor(), a.getx(), a.gety()); anim = a; anim.draw(g); anim.addtime(dt); public void setcolor(color c) { anim.setcolor(c); public Color getcolor() { return anim.getcolor(); Container static class FlyingMove extends Container { double vx, vy; public FlyingMove(Animation a, double vx1, double vy1) { super(a); vx = vx1; vy = vy1; super.addtime(dt); gx += vx * dt; gy += vy * dt; if (gx<0.0 && vx < 0.0) { vx = -vx; if (gx>400.0 && vx > 0.0) { vx = -vx; if (gy<0.0 && vy < 0.0) { vy = -vy; if (gy>300.0 && vy > 0.0) { vy = -vy; anim.moveto(gx, gy); static class CircleMove extends Container { double rad, vtheta, theta = 0; 15

public CircleMove(Animation a, double r, double vt) { super(a); rad = r; vtheta = vt; anim.moveto(gx+rad*math.cos(theta), gy+rad*math.sin(theta)); anim.draw(g); super.addtime(dt); theta += vtheta * dt; static class ChgColor extends Container { Color[] colors; double time = 0, period; public ChgColor(Animation a, Color[] c, double p) { super(a); colors = c; period = p; if(c.length == 0) throw new RuntimeException("empty color array"); super.addtime(dt); time += dt; anim.setcolor(colors[(int)(time/period) % colors.length]); public void moveto(double x, double y) { anim.moveto(x, y); public double getx() { return anim.getx(); public double gety() { return anim.gety(); public void setcolor(color c) { Container Figure static class AnimGroup extends Figure { Animation[] a = new Animation[20]; int count = 0; public AnimGroup(double x, double y) { super(color.black, x, y); public void add(animation anim) { if(count+1 < a.length) a[count++] = anim; for(int i = 0; i < count; ++i) { double x = a[i].getx(), y = a[i].gety(); a[i].moveto(x+gx, y+gy); a[i].draw(g); a[i].moveto(x, y); for(int i = 0; i < count; ++i) a[i].addtime(dt);? 16

3 /home/kuno/work/r10sample4.java 2 3 17