-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWindowController.java
More file actions
91 lines (74 loc) · 2.52 KB
/
WindowController.java
File metadata and controls
91 lines (74 loc) · 2.52 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.StackPane;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import java.net.URL;
import java.util.HashMap;
public class WindowController extends Application {
MacSim sim;
Parent root;
@FXML
private Label gdpLabel;
private Label popLabel;
private Label empLabel;
private Label comLabel;
@FXML
private Label curTime;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws InterruptedException, java.io.IOException {
URL location = getClass().getResource("WindowController.fxml");
FXMLLoader fxmlLoader = new FXMLLoader(location);
root = fxmlLoader.load();
//System.out.println("NODE:" + root);
primaryStage.setTitle("MacSim");
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
sim = new MacSim(this);
sim.startSimulation();
}
// ______________________________________________________
// UI Updates
public void update(MacSim sim) {
updateOverview(sim);
updateTime(sim);
}
@FXML
private void updateOverview(MacSim sim) {
if(gdpLabel == null)
gdpLabel = (Label) root.lookup("#gdp");
if(popLabel == null)
popLabel = (Label) root.lookup("#pop");
if(empLabel == null)
empLabel = (Label) root.lookup("#emp");
if(comLabel == null)
comLabel = (Label) root.lookup("#com");
gdpLabel.setText(Long.toString(sim.country.economy.gdp));
popLabel.setText(Long.toString(sim.country.pop.totalPop));
empLabel.setText(Long.toString(sim.country.pop.employed));
comLabel.setText(Long.toString(sim.country.economy.companies.size()));
}
@FXML
private void updateTime(MacSim sim) {
if(curTime == null)
curTime = (Label) root.lookup("#curTime");
curTime.setText(sim.year + " | " + sim.quarter + " | " + sim.tick%25);
}
public void test(ActionEvent actionEvent) {
MacSim.log(5, "TESTING 123");
}
public void sim(ActionEvent actionEvent) throws InterruptedException {
MacSim.sim.sim();
}
}