1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
package aufgaben.blatt1;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import aufgaben.Aufgabe;
import misc.Utils;
public class Aufgabe2b40 extends Aufgabe {
private final int width = 500, height = 500;
private boolean done = false;
private String name;
public Aufgabe2b40() {
name = "Blatt 1 - 2b40";
this.setSize(width, height);
this.setTitle("Blatt 1 - Aufgabe 2b - 40 Objekte");
this.addWindowListener(
new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
System.out.println("close");
done = true;
}
}
);
}
@Override
public boolean done() {
return done;
}
public void paint(Graphics g) {
int x, y;
for(int i = 0; i<40; i++) {
x = Utils.randomInt(0, width);
y = Utils.randomInt(0, height);
switch(Utils.randomInt(0, 8)) {
case 0:
g.drawRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
break;
case 1:
g.fillRect(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
break;
case 2:
g.drawArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
break;
case 3:
g.fillArc(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y), Utils.randomInt(0, 360), Utils.randomInt(0, 360));
break;
case 4:
g.drawOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
break;
case 5:
g.fillOval(x, y, Utils.randomInt(0, width-x), Utils.randomInt(0, height-y));
break;
case 6:
g.drawPolygon(getPolygon());
break;
case 7:
g.fillPolygon(getPolygon());
break;
case 8:
g.drawLine(Utils.randomInt(0, width), Utils.randomInt(0, height), Utils.randomInt(0, width), Utils.randomInt(0, height));
break;
}
g.setColor(new Color(Utils.randomInt(0, 255), Utils.randomInt(0, 255), Utils.randomInt(0, 255)));
}
}
private Polygon getPolygon() {
int bla = Utils.randomInt(1, 100);
int[] x = new int[bla], y = new int[bla];
for(int i = 0; i<bla; i++) {
x[i] = Utils.randomInt(0, width);
y[i] = Utils.randomInt(0, height);
}
return new Polygon(x, y, bla);
}
@Override
public String getName() {
return name;
}
@Override
public void init() {
// TODO Auto-generated method stub
}
}
|