-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSongLib.java
More file actions
66 lines (47 loc) · 1.7 KB
/
SongLib.java
File metadata and controls
66 lines (47 loc) · 1.7 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
//Itamar Levi, Young Choi
package SongLib;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
//import javafx.scene.layout.AnchorPane;
import javafx.stage.WindowEvent;
import java.io.FileWriter;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.*;
public class SongLib extends Application {
public static Stage primaryStage;
@Override
public void start(Stage primaryStage) throws Exception{
// Parent root = FXMLLoader.load(getClass().getResource("hellofx.fxml"));
// FXMLLoader loader= new FXMLLoader();
FXMLLoader loader = new FXMLLoader(getClass().getResource("SongLib.fxml"));
Parent root = (Parent) loader.load();
Controller controller = loader.getController();
controller.initialize(primaryStage);
Scene scene = new Scene(root,700, 500);
primaryStage.setScene(scene);
primaryStage.setResizable(false);
primaryStage.show();
primaryStage.getScene().getWindow().addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, arg0 -> {
try {
closeWindowEvent(arg0);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
}
private void closeWindowEvent(WindowEvent event) throws Exception{
JSONObject obj=(JSONObject) Controller.getSong;
FileWriter file = new FileWriter("songs.json");
file.write(obj.toJSONString());
file.flush();
//file.close();
}
public static void main(String[] args) {
launch(args);
}
}