Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2a634e3

Browse filesBrowse files
committed
revised ch16
1 parent f267d4d commit 2a634e3
Copy full SHA for 2a634e3

File tree

Expand file treeCollapse file tree

6 files changed

+18
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

6 files changed

+18
-19
lines changed
Open diff view settings
Collapse file

‎ch16/BlinkingPolygon.java‎

Copy file name to clipboardExpand all lines: ch16/BlinkingPolygon.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public void step() {
3434
// toggle visibility every 10 steps
3535
count++;
3636
if (count == 10) {
37-
count = 0;
3837
visible = !visible;
38+
count = 0;
3939
}
4040
}
4141

Collapse file
+4-4Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
/**
66
* Specialization of Polygon that has a color and the ability to draw itself.
77
*/
8-
public class ColorPolygon extends Polygon implements Actor {
8+
public class DrawablePolygon extends Polygon implements Actor {
99

10-
protected Color color;
10+
public Color color;
1111

1212
/**
1313
* Creates an empty polygon.
1414
*/
15-
public ColorPolygon() {
15+
public DrawablePolygon() {
1616
super();
1717
color = Color.GRAY;
1818
}
@@ -38,7 +38,7 @@ public void step() {
3838
* @param args command-line arguments
3939
*/
4040
public static void main(String[] args) {
41-
ColorPolygon p = new ColorPolygon();
41+
DrawablePolygon p = new DrawablePolygon();
4242
p.addPoint(57, 110);
4343
p.addPoint(100, 35);
4444
p.addPoint(143, 110);
Collapse file

‎ch16/Drawing.bak‎

Copy file name to clipboardExpand all lines: ch16/Drawing.bak
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ public class Drawing extends Canvas {
2525
/**
2626
* Adds a new actor to the drawing.
2727
*
28-
* @param cp the object to add
28+
* @param dp the object to add
2929
*/
30-
public void add(ColorPolygon cp) {
31-
list.add(cp);
30+
public void add(ColorPolygon dp) {
31+
list.add(dp);
3232
}
3333

3434
/**
@@ -47,17 +47,17 @@ public class Drawing extends Canvas {
4747
*/
4848
@Override
4949
public void paint(Graphics g) {
50-
for (ColorPolygon cp : list) {
51-
cp.draw(g);
50+
for (ColorPolygon dp : list) {
51+
dp.draw(g);
5252
}
5353
}
5454

5555
/**
5656
* Calls the step method of each actor and updates the drawing.
5757
*/
5858
public void step() {
59-
for (ColorPolygon cp : list) {
60-
cp.step();
59+
for (ColorPolygon dp : list) {
60+
dp.step();
6161
}
6262
repaint();
6363
}
Collapse file

‎ch16/RegularPolygon.java‎

Copy file name to clipboardExpand all lines: ch16/RegularPolygon.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* A polygon that is equiangular (all angles are equal in measure) and
55
* equilateral (all sides have the same length). It also has a color.
66
*/
7-
public class RegularPolygon extends ColorPolygon {
7+
public class RegularPolygon extends DrawablePolygon {
88

99
public static final String[] NAMES = {null, null, null,
1010
"Triangle", "Square", "Pentagon", "Hexagon",
Collapse file

‎ch16/Sim1.java‎

Copy file name to clipboardExpand all lines: ch16/Sim1.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public class Sim1 {
1414
public static void main(String[] args) {
1515

1616
// create some regular polygons
17-
ColorPolygon p1 = new RegularPolygon(3, 50, Color.GREEN);
18-
ColorPolygon p2 = new RegularPolygon(6, 50, Color.ORANGE);
19-
ColorPolygon p3 = new RegularPolygon(360, 50, Color.BLUE);
17+
DrawablePolygon p1 = new RegularPolygon(3, 50, Color.GREEN);
18+
DrawablePolygon p2 = new RegularPolygon(6, 50, Color.ORANGE);
19+
DrawablePolygon p3 = new RegularPolygon(360, 50, Color.BLUE);
2020

2121
// move them out of the corner
2222
p1.translate(100, 80);
Collapse file

‎ch16/Sprite.java‎

Copy file name to clipboardExpand all lines: ch16/Sprite.java
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
public class Sprite implements Actor, KeyListener {
1313

1414
private Image image;
15-
1615
private int xpos;
1716
private int ypos;
1817
private int dx;
@@ -26,10 +25,10 @@ public class Sprite implements Actor, KeyListener {
2625
* @param ypos initial Y coordinate
2726
*/
2827
public Sprite(String path, int xpos, int ypos) {
28+
this.xpos = xpos;
29+
this.ypos = ypos;
2930
try {
3031
this.image = ImageIO.read(new File(path));
31-
this.xpos = xpos;
32-
this.ypos = ypos;
3332
} catch (IOException e) {
3433
e.printStackTrace();
3534
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.