8000 revised ch16 examples · ilhamgunawan/ThinkJavaCode2@869bade · GitHub
[go: up one dir, main page]

Skip to content

Commit 869bade

Browse files
committed
revised ch16 examples
1 parent 1407390 commit 869bade

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

ch16/BlinkingPolygon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class BlinkingPolygon extends RegularPolygon {
88

99
protected boolean visible;
10-
private int count;
10+
protected int count;
1111

1212
/**
1313
* Constructs a blinking polygon.

ch16/ColorPolygon.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,17 @@ public void step() {
3232
// do nothing
3333
}
3434

35+
/**
36+
* Test code that creates a ColorPolygon.
37+
*
38+
* @param args command-line arguments
39+
*/
40+
public static void main(String[] args) {
41+
ColorPolygon p = new ColorPolygon();
42+
p.addPoint(57, 110);
43+
p.addPoint(100, 35);
44+
p.addPoint(143, 110);
45+
p.color = Color.GREEN;
46+
}
47+
3548
}

ch16/RegularPolygon.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public RegularPolygon(int nsides, int radius, Color color) {
5656
this.ypoints = new int[nsides];
5757
this.color = color;
5858

59-
// the angle (in radians) for each vertex
59+
// the amount to rotate for each vertex (in radians)
6060
double angle = 2.0 * Math.PI / nsides;
6161

6262
// rotation that makes the polygon right-side up
6363
double rotate = Math.PI / nsides + Math.PI / 2.0;
6464

65-
// compute x and y coordinates, centered around the origin
65+
// compute x and y coordinates, centered at the origin
6666
for (int i = 0; i < nsides; i++) {
6767
double x = radius * Math.cos(i * angle + rotate);
6868
xpoints[i] = (int) Math.round(x);

ch16/VideoGame.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ public class VideoGame implements ActionListener {
1616
* Set up the drawing and window frame.
1717
*/
1818
public VideoGame() {
19-
Sprite sprite = new Sprite("face-smile.png", 25, 150);
19+
Sprite sprite = new Sprite("face-smile.png", 50, 50);
2020
drawing = new Drawing(800, 600);
2121
drawing.add(sprite);
2222
drawing.addKeyListener(sprite);
23+
drawing.setFocusable(true);
2324
JFrame frame = new JFrame("Video Game");
2425
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
2526
frame.add(drawing);

0 commit comments

Comments
 (0)
0