forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
43 lines (35 loc) · 1.06 KB
/
Copy pathMain.java
File metadata and controls
43 lines (35 loc) · 1.06 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
import javax.swing.JFrame;
/**
* Example simulation of moving objects.
*/
public class Main {
/**
* Sets up the drawing, creates the actors, and runs the simulation.
*
* @param args command-line arguments
*/
public static void main(String[] args) {
// set up the drawing and add actors
Drawing drawing = new Drawing(800, 600);
drawing.add(new Triangle(25, 25, 25, 325, 425, 25));
drawing.add(new Triangle(500, 400, 530, 400, 500, 440));
// set up the window frame
JFrame frame = new JFrame("Drawing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(drawing);
frame.pack();
frame.setVisible(true);
// main simulation loop
while (true) {
// update the drawing
drawing.nextact();
drawing.repaint();
// delay the simulation
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// do nothing
}
}
}
}