-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCityscapeComponent.java
More file actions
110 lines (86 loc) · 3.04 KB
/
Copy pathCityscapeComponent.java
File metadata and controls
110 lines (86 loc) · 3.04 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
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
import java.awt.Color;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.Arc2D;
import java.awt.GradientPaint;
/**
* Class that creates instances of the classes that comprise the cityscape and delegates drawing the
* cityscape to these object.
*
* @author gcschmit
* @version 18 July 2014
*/
public class CityscapeComponent extends JComponent
{
// define the objects in your Cityscape as instance variables
// ...
private Cloud testCloud;
private Buildings testBuilding;
private Buildings testBuilding2;
private Buildings testBuilding3;
private Buildings testBuilding4;
private Buildings testBuilding5;
private Moon outerMoon;
int xVal = 0;
Color sunsetOrange = new Color(253, 94, 83);
Color shandy = new Color(255, 227, 115);
Color darkBlue = new Color(0,0,153);
Color lightBlue = new Color(51,255,255);
GradientPaint sunGradient = new GradientPaint(100,0,sunsetOrange,100,300,shandy);
GradientPaint oceanGradient = new GradientPaint(500, 500,lightBlue,500,1000,darkBlue);
// define the CityscapeComponent contructor and intiailize all instance variables
// ...
public CityscapeComponent(){
testCloud = new Cloud(600,100,400,100);
outerMoon = new Moon(sunGradient,oceanGradient,50);
testBuilding = new Buildings(200,220,400);
testBuilding2 = new Buildings(425,100,300);
testBuilding3 = new Buildings(530,200,450);
testBuilding4 = new Buildings(760,115,250);
testBuilding5 = new Buildings(50,135,350);
//centerMoon = new Moon(sandyBrown, 150);
//innerMoon = new Moon(shandy, 175);
}
/**
* This method is invoked by the Java Run-Time whenever the component needs to be redrawn.
* It does not need to be invoked explicitly.
*
* @param g a reference to the Graphics object used for all drawing operations
*
*/
@Override
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
outerMoon.draw(g2);
testBuilding.draw(g2);
testBuilding2.draw(g2);
testBuilding3.draw(g2);
testBuilding4.draw(g2);
testBuilding5.draw(g2);
testCloud.draw(g2);
//centerMoon.draw(g2);
//innerMoon.draw(g2);
// invoke the draw method on each object in your Cityscape
// ...
}
/**
* Animate the cityscape by updating the objects such that they appear to be animated when
* they are next drawn.
*
*/
public void nextFrame()
{
// update the objects in the cityscape so they are animated
// ...
if (xVal <=0){
xVal=600;
}
testCloud.changeX(xVal=xVal-25);
// request that the Java Runtime repaints this component by invoking its paintComponent method
// do not explicitly invoke the paintComponent method
repaint();
}
}