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 c3eb035

Browse filesBrowse files
committed
draw before step; whitespace
1 parent dbcdbc8 commit c3eb035
Copy full SHA for c3eb035

File tree

Expand file treeCollapse file tree

7 files changed

+26
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

7 files changed

+26
-21
lines changed
Open diff view settings
Collapse file

‎ch16/BlinkingPolygon.java‎

Copy file name to clipboardExpand all lines: ch16/BlinkingPolygon.java
+10-9Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@ public BlinkingPolygon(int nsides, int radius, Color color) {
2121
drawFlag = true;
2222
count = 0;
2323
}
24-
24+
25+
@Override
26+
public void draw(Graphics g) {
27+
if (drawFlag) {
28+
super.draw(g);
29+
}
30+
}
31+
2532
@Override
2633
public void step() {
27-
// every 10 steps toggle drawFlag
34+
// toggle drawFlag every 10 steps
2835
count++;
2936
if (count == 10) {
3037
count = 0;
3138
drawFlag = !drawFlag;
3239
}
3340
}
34-
35-
@Override
36-
public void draw(Graphics g) {
37-
if (drawFlag) {
38-
super.draw(g);
39-
}
40-
}
41+
4142
}
Collapse file

‎ch16/MovingPolygon.java‎

Copy file name to clipboardExpand all lines: ch16/MovingPolygon.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ public void step() {
5252
// move one step
5353
translate(dx, dy);
5454
}
55+
5556
}
Collapse file

‎ch16/RegularPolygon.java‎

Copy file name to clipboardExpand all lines: ch16/RegularPolygon.java
+9-8Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class RegularPolygon extends Polygon implements Actor {
2020
* @param nsides the number of sides
2121
*/
2222
public RegularPolygon(int nsides) {
23-
this(nsides, 6);
23+
this(nsides, 50);
2424
}
2525

2626
/**
@@ -69,23 +69,23 @@ public RegularPolygon(int nsides, int radius, Color color) {
6969
// compute x and y coordinates, centered around the origin
7070
for (int i = 0; i < nsides; i++) {
7171
double x = radius * Math.cos(i * angle + rotate);
72-
xpoints[i] = (int) Math.round(x);
72+
xpoints[i] = (int) Math.round(x);
7373
double y = radius * Math.sin(i * angle + rotate);
74-
ypoints[i] = (int) Math.round(y);
74+
ypoints[i] = (int) Math.round(y);
7575
}
7676
}
7777

78-
@Override
79-
public void step() {
80-
// do nothing
81-
}
82-
8378
@Override
8479
public void draw(Graphics g) {
8580
g.setColor(color);
8681
g.fillPolygon(this);
8782
}
8883

84+
@Override
85+
public void step() {
86+
// do nothing
87+
}
88+
8989
@Override
9090
public String toString() {
9191
StringBuilder str = new StringBuilder();
@@ -110,4 +110,5 @@ public String toString() {
110110
str.append(']');
111111
return str.toString();
112112
}
113+
113114
}
Collapse file

‎ch16/Sim1.java‎

Copy file name to clipboardExpand all lines: ch16/Sim1.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ public static void main(String[] args) {
3737
frame.pack();
3838
frame.setVisible(true);
3939
}
40+
4041
}
Collapse file

‎ch16/Sim2.java‎

Copy file name to clipboardExpand all lines: ch16/Sim2.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,5 @@ public static void main(String[] args) {
5454
}
5555
}
5656
}
57+
5758
}
Collapse file

‎ch16/Sim3.java‎

Copy file name to clipboardExpand all lines: ch16/Sim3.java
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void actionPerformed(ActionEvent e) {
4848
toolkit.sync();
4949
drawing.step();
5050
}
51-
51+
5252
/**
5353
* Create and start the timer.
5454
*
@@ -59,4 +59,5 @@ public static void main(String[] args) {
5959
Timer timer = new Timer(1000 / 30, sim);
6060
timer.start();
6161
}
62+
6263
}
Collapse file

‎ch16/WhackAMole.java‎

Copy file name to clipboardExpand all lines: ch16/WhackAMole.java
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,16 @@ public void actionPerformed(ActionEvent e) {
4242
toolkit.sync();
4343
drawing.step();
4444
}
45-
45+
4646
/**
4747
* Create and start the timer.
4848
*
4949
* @param args command-line arguments
5050
*/
5151
public static void main(String[] args) {
5252
WhackAMole sim = new WhackAMole();
53-
54-
// TODO: Can we explain the 1000 / 30 or write it so it's obvious?
5553
Timer timer = new Timer(1000 / 30, sim);
5654
timer.start();
5755
}
56+
5857
}

0 commit comments

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