Skip to content

Commit c5d2c63

Browse files
committed
sync after sleep
1 parent 3cc6dd6 commit c5d2c63

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

ch16/Main.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import java.awt.Toolkit;
12
import java.io.File;
23
import java.io.FileNotFoundException;
34
import java.util.ArrayList;
@@ -92,23 +93,25 @@ public static Grid readFile(String path) {
9293
*/
9394
public static void main(String[] args) {
9495

95-
// create the grid
96+
// create the grid drawing
9697
Grid grid;
9798
if (args.length != 1) {
9899
grid = example();
99100
} else {
100101
grid = readFile(args[0]);
101102
}
102-
103-
// set up the drawing
104103
Drawing drawing = new Drawing(grid);
104+
105+
// set up the window frame
105106
JFrame frame = new JFrame("Drawing");
106107
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
108+
frame.setResizable(false);
107109
frame.add(drawing);
108110
frame.pack();
109111
frame.setVisible(true);
110112

111113
// main simulation loop
114+
Toolkit toolkit = frame.getToolkit();
112115
while (true) {
113116

114117
// update the drawing
@@ -118,6 +121,7 @@ public static void main(String[] args) {
118121
// delay the simulation
119122
try {
120123
Thread.sleep(500);
124+
toolkit.sync();
121125
} catch (InterruptedException e) {
122126
// do nothing
123127
}

0 commit comments

Comments
 (0)