-
Notifications
You must be signed in to change notification settings - Fork 0
/
JavaFXCaller.java
71 lines (59 loc) · 2.4 KB
/
JavaFXCaller.java
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
package //Add your own Package name here;
import java.io.*;
import java.util.LinkedHashMap;
import java.util.Map;
/**
*
* @author Harishankar Vinod (HVEPYC)
*/
public class JavaFXCaller {
//Returns Current Working Directory of the Java Project
private static final String CWD = System.getProperty("user.dir");
private String pathtotxt;
//Define Graph Types as:
//1. Line Graph
//2. Bar Chart
//3. Pie Chart
public JavaFXCaller(int ChartType) {
//Creates a File which is to be read by the JavaFX Jar File later.
if (ChartType == 1) {
this.pathtotxt = CWD+"\\ForJavaFXLine.txt";
}
else if(ChartType == 2) {
this.pathtotxt = CWD+"\\ForJavaFXBar.txt";
}
else if(ChartType == 3) {
this.pathtotxt = CWD+"\\ForJavaFXPie.txt";
}
File JavaFXFile = new File(pathtotxt);
try {
JavaFXFile.createNewFile();
} catch (IOException e) {}
}
public void JavaFXChartGen(LinkedHashMap<String, String> A) {
try {
PrintWriter WriteToFile = new PrintWriter(new FileOutputStream(this.pathtotxt));
for (Map.Entry<String, String> entry : A.entrySet()) {
String parameter = entry.getKey()+":"+entry.getValue();
WriteToFile.println(parameter);
}
WriteToFile.close();
} catch (FileNotFoundException e) {}
//Runs the Command to execute the Java Jar file
String command = "cmd /C \"java -jar \""+CWD+"\\javaFXchartDisplay-1.0.jar\"\"";
//Issues the Command to CMD
try {
Runtime.getRuntime().exec(command);
} catch (IOException ioe) {
System.out.println("Some Big Problems");}
}
}
//References used for the creation of this Java File:
//https://www.javatpoint.com/how-to-create-a-file-in-java
//https://www.geeksforgeeks.org/write-hashmap-to-a-text-file-in-java/
//https://stackoverflow.com/questions/10514473/how-to-convert-a-string-to-a-hashmap
//https://stackoverflow.com/questions/17910377/hashmap-keyset-automatically-sorted
//https://www.digitalocean.com/community/tutorials/thread-sleep-java
//https://www.javatpoint.com/how-to-delete-a-file-in-java
//https://stackoverflow.com/questions/1816673/how-do-i-check-if-a-file-exists-in-java
//https://jenkov.com/tutorials/javafx/piechart.html