-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFarmReport.java
More file actions
165 lines (130 loc) · 4.26 KB
/
FarmReport.java
File metadata and controls
165 lines (130 loc) · 4.26 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/**
* Main.java created by Bo
*
* Author: Bo Li (bli379@wisc.edu) Date: 4/21/2020
*
*
* Course: CS400 Semester: Spring 2020 Lecture: 001
*
* IDE: Eclipse IDE For Java Developers Version: 291942 (4.14.0)
*/
/**
* Main
*
* @author Bo
*
*/
import java.io.IOException;
import java.util.List;
import javafx.application.Application;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Font;
import javafx.stage.Stage;
public class FarmReport extends Application {
// store any command-line arguments that were entered.
// NOTE: this.getParameters().getRaw() will get these also
// private List<String> args;
private static final int WINDOW_WIDTH = 840;
private static final int WINDOW_HEIGHT = 600;
private static final String APP_TITLE = "Farm Report";
MilkData milkData;
/**
* @param milkData
*/
public FarmReport(MilkData milkData) {
this.milkData = milkData;
}
@Override
public void start(Stage primaryStage) throws Exception {
// save args example
// args = this.getParameters().getRaw();
// title
Label title = new Label("Farm Report");
title.setFont(new Font("Arial", 20));
// create a horizontal box
HBox hbox1 = new HBox();
HBox hbox2 = new HBox();
hbox1.setSpacing(10);
hbox2.setSpacing(10);
// create a vbox
VBox vbox = new VBox();
vbox.setSpacing(20);
Label prompt1 = new Label("Farm ID:");
Label prompt2 = new Label("Year: ");
TextField farmid = new TextField();
TextField year = new TextField();
farmid.setPromptText("Type ID here");
year.setPromptText("Type Year here");
farmid.setMaxWidth(300);
year.setMaxWidth(300);
Button confirm = new Button("Confirm");
Button ex = new Button("Export to file");
// Handler
FarmReportHandler handler = new FarmReportHandler(milkData, vbox, farmid, year);
ex.addEventHandler(ActionEvent.ACTION, (e) -> {
try {
milkData.writeMilkData();
EventLog.getInstance().log("File exported");
} catch (IOException exc) {
System.out.println("Error when export as file!");
}
});
// register event handler for button
confirm.setOnAction(handler);
// add to hbox
hbox1.getChildren().addAll(prompt1, farmid,confirm);
hbox2.getChildren().addAll(prompt2, year, ex);
vbox.setPadding(new Insets(10, 0, 0, 10));
vbox.getChildren().addAll(title, hbox1, hbox2);
Scene mainScene = new Scene(vbox, WINDOW_WIDTH, WINDOW_HEIGHT);
// set css
mainScene.getStylesheets().add(getClass().getResource("FarmReportStyle.css").toExternalForm());
// Add the stuff and set the primary stage
primaryStage.setTitle(APP_TITLE);
primaryStage.setScene(mainScene);
primaryStage.show();
}
public static class Milk {
private final SimpleStringProperty month;
private final SimpleIntegerProperty weight;
private final SimpleDoubleProperty percentage;
Milk(String month, Integer weight, Double percentage) {
this.month = new SimpleStringProperty(month);
this.weight = new SimpleIntegerProperty(weight);
this.percentage = new SimpleDoubleProperty(percentage);
}
public String getMonth() {
return month.get();
}
public Integer getWeight() {
return weight.get();
}
public Double getPercentage() {
return percentage.get();
}
}
/**
* @param args
*/
public static void main(String[] args) {
launch(args);
}
}