1 import java.applet.*;
2 import java.awt.*;
3 import java.util.*;
4
5
6 public class Application extends Applet
7 {
8 Vector before,after;
9 Graphics g;
10
11 public void init()
12 {
13 primitive object1,object2;
14 visitor bewegung;
15 int i;
16 Random auswahl=new Random();
17
18 g=getGraphics();
19 before=new Vector();
20 after=new Vector();
21
22 for(i=1;i<=10;i++)
23 {
24 switch(auswahl.nextInt()%3)
25 {
26 case 0:
27 {
28 float x=auswahl.nextFloat()*200;
29 float y=auswahl.nextFloat()*100;
30 bewegung=new movevisitor(x,y);
31 break;
32 }
33
34 case 1:
35 {
36 float x1=auswahl.nextFloat()*200;
37 float y1=auswahl.nextFloat()*100;
38 float x2=auswahl.nextFloat()*200;
39 float y2=auswahl.nextFloat()*100;
40 bewegung=new mirrorvisitor(x1,y1,x2,y2);
41 break;
42 }
43
44 default:
45 {
46 float c1=auswahl.nextFloat()*200;
47 float c2=auswahl.nextFloat()*100;
48 float a=auswahl.nextFloat()*2;
49 bewegung=new rotatevisitor(c1,c2,a);
50 }
51 }
52
53 switch(auswahl.nextInt()%3)
54 {
55 case 0:
56 {
57 float x=auswahl.nextFloat()*100+320;
58 float y=auswahl.nextFloat()*100+240;
59 object1=new point(x,y);
60 object2=new point(x,y);
61 break;
62 }
63
64 case 1:
65 {
66 float x1=auswahl.nextFloat()*100+320;
67 float y1=auswahl.nextFloat()*100+240;
68 float x2=auswahl.nextFloat()*100+320;
69 float y2=auswahl.nextFloat()*100+340;
70 object1=new line(x1,y1,x2,y2);
71 object2=new line(x1,y1,x2,y2);
72 break;
73 }
74
75 default:
76 {
77 float c1=auswahl.nextFloat()*100+320;
78 float c2=auswahl.nextFloat()*100+240;
79 float r =auswahl.nextFloat()*100;
80 object1=new circle(c1,c2,r);
81 object2=new circle(c1,c2,r);
82 }
83 }
84
85 before.addElement(object1);
86 object2.receive(bewegung);
87 after.addElement(object2);
88 }
89 }
90
91 public void paint(Graphics g)
92 {
93 int i;
94 int n=before.size();
95 primitive object;
96
97 for(i=0;i<n;i++)
98 {
99 try
100 {
101 object=(primitive) before.elementAt(i);
102 object.zeichne(g);
103 Thread.sleep(500);
104 g.setColor(Color.red);
105 object=(primitive) after.elementAt(i);
106 object.zeichne(g);
107 Thread.sleep(1000);
108 g.clearRect(0,0,800,600);
109 g.setColor(Color.black);
110
111 }
112 catch(InterruptedException a)
113 {
114 //hier passiert nix
115 }
116 }
117 }
118 }