-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathPicture.java
More file actions
129 lines (106 loc) · 3.14 KB
/
Copy pathPicture.java
File metadata and controls
129 lines (106 loc) · 3.14 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
* This class represents a simple picture. You can draw the picture using
* the draw method. But wait, there's more: being an electronic picture, it
* can be changed. You can set it to black-and-white display and back to
* colors (only after it's been drawn, of course).
*
* This class was written as an early example for teaching Java with BlueJ.
*
* @author Michael Kölling and David J. Barnes
* @version 1.1 (24 May 2001)
*/
public class Picture
{
private Square wall;
private Square window;
private Triangle roof;
private Circle sun;
private Square window2;
private Square door;
private Triangle tree;
private Square treeTrunk;
/**
* Constructor for objects of class Picture
*/
public Picture()
{
// nothing to do... instance variables are automatically set to null
}
/**
* Draw this picture.
*/
public void draw()
{
wall = new Square();
wall.moveVertical(80);
wall.changeSize(100);
wall.makeVisible();
window = new Square();
window.changeColor("black");
window.moveHorizontal(10);
window.moveVertical(100);
window.makeVisible();
roof = new Triangle();
roof.changeSize(50, 140);
roof.moveHorizontal(60);
roof.moveVertical(70);
roof.makeVisible();
sun = new Circle();
sun.changeColor("yellow");
sun.moveHorizontal(180);
sun.moveVertical(-10);
sun.changeSize(60);
sun.makeVisible();
window2 = new Square();
window2.changeColor("black");
window2.moveHorizontal(60);
window2.moveVertical(100);
window2.makeVisible();
door = new Square();
door.changeColor("black");
door.moveHorizontal(35);
door.moveVertical(150);
door.makeVisible();
door = new Square();
door.changeColor("black");
door.moveHorizontal(35);
door.moveVertical(135);
door.makeVisible();
treeTrunk = new Square();
treeTrunk.changeColor("brown");
treeTrunk.moveHorizontal(195);
treeTrunk.moveVertical(200);
treeTrunk.makeVisible();
tree = new Triangle();
tree.changeSize(140, 70);
tree.moveHorizontal(220);
tree.moveVertical(105);
tree.makeVisible();
}
/**
* Change this picture to black/white display
*/
public void setBlackAndWhite()
{
if(wall != null) // only if it's painted already...
{
wall.changeColor("black");
window.changeColor("white");
roof.changeColor("black");
sun.changeColor("black");
}
}
/**
* Change this picture to use color display
*/
public void setColor()
{
if(wall != null) // only if it's painted already...
{
wall.changeColor("red");
window.changeColor("black");
roof.changeColor("green");
sun.changeColor("yellow");
}
}
}