-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBirdsGUI.java
More file actions
70 lines (49 loc) · 1.54 KB
/
BirdsGUI.java
File metadata and controls
70 lines (49 loc) · 1.54 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package sim.app.birds;
import sim.engine.*;
import sim.display.*;
import sim.portrayal.continuous.*;
import java.awt.*;
import javax.swing.*;
public class BirdsGUI extends GUIState {
public Display2D display;
public JFrame displayFrame;
ContinuousPortrayal2D birdPortrayal = new ContinuousPortrayal2D();
public static void main(String[] args) {
Console c = new Console(new BirdsGUI());
c.setVisible(true);
}
public BirdsGUI() { super(new BirdsModel(System.currentTimeMillis())); }
public BirdsGUI(SimState state) { super(state); }
public static String getName() { return "Birds"; }
public Object getSimulationInspectedObject() { return state; }
public void start() {
super.start();
setupPortrayal();
}
public void load(SimState state) {
super.load(state);
setupPortrayal();
}
public void setupPortrayal() {
birdPortrayal.setPortrayalForAll( new sim.portrayal.simple.OvalPortrayal2D(Color.white, 5) );
birdPortrayal.setField(((BirdsModel)state).getWorld());
display.reset();
display.repaint();
}
public void init(Controller c) {
super.init(c);
display = new Display2D(BirdsModel.WORLD_SIZE_X, BirdsModel.WORLD_SIZE_Y,this,1);
//display.setScale(10);
displayFrame = display.createFrame();
c.registerFrame(displayFrame);
displayFrame.setVisible(true);
display.attach(birdPortrayal, "Birds");
display.setBackdrop(Color.black);
}
public void quit() {
super.quit();
if( displayFrame != null ) displayFrame.dispose();
displayFrame = null;
display = null;
}
}