forked from Toyoyou/homework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTenCircles.java
More file actions
52 lines (44 loc) · 1.27 KB
/
Copy pathTenCircles.java
File metadata and controls
52 lines (44 loc) · 1.27 KB
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
import objectdraw.*;
import java.awt.*;
public class TenCircles extends WindowController {
private final int numMaxCircle = 10;
private FramedOval[] circles;
private int count;
@Override public void begin(){
circles = new FramedOval[10];
count = 0;
}
@Override public void onMouseClick(Location point){
for(int i = 0; i < count; i++){
if(circles[i].contains(point)){
setColor();
return;
}
}
if(count>10)count = 0;
circles[count] = new FramedOval(point.getX()-25,point.getY()-25,50,50,canvas);
count++;
}
private void setColor(){
Color c = getRandomColor();
for(int i = 0; i < count; i++){
circles[i].setColor(c);
}
}
private Color getRandomColor(){
RandomIntGenerator rnd = new RandomIntGenerator(0,4);
int i = rnd.nextValue();
switch(i){
case 0:
return Color.red;
case 1:
return Color.blue;
case 2:
return Color.green;
case 3:
return Color.yellow;
default:
return Color.black;
}
}
}