Skip to content
Snippets Groups Projects
Commit 918a0615 authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

Tried creating a thread, having some difficulty

parent c3d419ae
No related branches found
No related tags found
No related merge requests found
...@@ -2,12 +2,17 @@ package com.application.GUI; ...@@ -2,12 +2,17 @@ package com.application.GUI;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.*; import javafx.scene.*;
import javafx.scene.chart.LineChart;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.*; import javafx.scene.layout.*;
import javafx.stage.*; import javafx.stage.*;
import org.checkerframework.checker.units.qual.K;
import java.util.Map;
import static com.application.DB.Constants.*; import static com.application.DB.Constants.*;
import static com.application.DB.DB.setInputParameters;
import static com.application.GUI.LineChartFunctionality.loadSingleSeries;
/** /**
* This class handles the popup input window * This class handles the popup input window
...@@ -79,15 +84,77 @@ public class InputPopUpWindow { ...@@ -79,15 +84,77 @@ public class InputPopUpWindow {
window.close(); window.close();
// Call på getKwh()
class KwhThread implements Runnable {
Map<Integer, Map<String, Number>> dataVariable;
private volatile boolean finished;
@Override
public void run() {
try{
dataVariable = setInputParameters();
} catch (Exception ex) {
ex.printStackTrace();
}
finished = true;
synchronized (this){
this.notify();
}
}
public Map<Integer, Map<String, Number>> getDataVariable() throws InterruptedException {
synchronized (this){
if(!finished)
this.wait();
}
return dataVariable;
}
}
KwhThread kwhThread = new KwhThread();
Thread thread = new Thread(kwhThread);
thread.setName("GetKwhThread");
thread.start();
try { try {
LineChartFunctionality.loadSingleSeries(); loadSingleSeries(kwhThread.getDataVariable());
//LineChartFunctionality.loadMultipleSeries(); } catch (Exception ex) {
ex.printStackTrace();
}
/*
// Fungerende ny thread!!@@@@@
try{
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
loadSingleSeries(setInputParameters());
//loadSingleSeries();
//loadMultipleSeries();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
thread.start();
//thread.join();
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
*/
}); });
VBox layout = new VBox(10); VBox layout = new VBox(10);
......
...@@ -26,7 +26,11 @@ public class LineChartFunctionality { ...@@ -26,7 +26,11 @@ public class LineChartFunctionality {
lineChart.setTitle("Drying Processes"); lineChart.setTitle("Drying Processes");
} }
public LineChart<String, Number> getLineChart() { public static void setLineChart(LineChart<String, Number> lineChart) {
LineChartFunctionality.lineChart = lineChart;
}
public static LineChart<String, Number> getLineChart() {
return lineChart; return lineChart;
} }
...@@ -39,13 +43,14 @@ public class LineChartFunctionality { ...@@ -39,13 +43,14 @@ public class LineChartFunctionality {
} }
public static void loadSingleSeries() throws Exception { public static LineChart<String, Number> loadSingleSeries(Map<Integer, Map<String, Number>> userInput) throws Exception {
clearLineChart(); clearLineChart();
Map<Integer, Map<String, Number>> kWh = DB.setInputParameters(); //Map<Integer, Map<String, Number>> kWh = userInput;
//Map<Integer, Map<String, Number>> kWh = DB.setInputParameters();
//System.out.println(kWh.size()); //System.out.println(kWh.size());
for (Map.Entry<Integer, Map<String, Number>> entryKwh : kWh.entrySet()) { for (Map.Entry<Integer, Map<String, Number>> entryKwh : userInput.entrySet()) {
Map data = entryKwh.getValue(); Map data = entryKwh.getValue();
//System.out.println(data.size()); //System.out.println(data.size());
...@@ -67,6 +72,7 @@ public class LineChartFunctionality { ...@@ -67,6 +72,7 @@ public class LineChartFunctionality {
} }
updateLineChart(newSeries); updateLineChart(newSeries);
} }
return getLineChart();
} }
public static void loadMultipleSeries() throws Exception { public static void loadMultipleSeries() throws Exception {
......
...@@ -104,6 +104,7 @@ ...@@ -104,6 +104,7 @@
#inputButtonStart { #inputButtonStart {
-fx-pref-width: infinity; -fx-pref-width: infinity;
-fx-translate-y: 10;
-fx-pref-height: 25; -fx-pref-height: 25;
-fx-font-size: 20; -fx-font-size: 20;
-fx-font-family: Arial; -fx-font-family: Arial;
......
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment