0

I am creating a live graphing application, using a library called 'LiveGraph', which I stumbled upon. Essentially, the LiveGraph application is a GUI that keeps on reading from a text file with data, and updates the corresponding graph.

Here is a snippet of the code I have (explanations below:

for (VisualDisplay vd : visDisplayElements) {
    vd.display();
    System.out.println("Done executing.");
}

while (!dcm.done) {
    String packet = dcm.run();
    HashMap<String, Integer> dataMap = initializeMap (packet, config.delimiter, config.colNames);
    for (VisualDisplay element : visDisplayElements) {
        element.receivedDataSet(dataMap);
    }
}

The first for loop essentially goes through the list of graphs and loads up the GUI for each of them. The while loop afterwards essentially keeps polling forever for data through the network.

Now here's the scenario: When I am only displaying the graphs (i.e., if I comment out the while loop), the graphs display and open up (but obviously don't display anything because nothing is polling). However, with all the code as shown below, the GUI windows for the graphs open up, but turn out completely gray, with no content. If I try resizing or interacting with them in any way, the application freezes, and I have to force quit.

I'm narrowed this down to the issue that threading is somehow a problem here. The while-loop will keep running forever, and maybe the GUI's will not run properly due to that. I am looking for a solution to this, that maybe involves threading. I'm tried a few basic things, such as running the display and polling each as separate threads, but I was getting nowhere.

stoneman
  • 25
  • 5
  • You're blocking the UI frameworks event dispatching thread, which is responsible for among other things, process paint events. The solution will depend on the framework you are using – MadProgrammer Sep 28 '15 at 03:40
  • @MadProgrammer The framework I am using is LiveGraph (http://www.live-graph.org) – stoneman Sep 28 '15 at 03:41
  • 1
    Yep, but's based on a framework, Swing I think. Have a look at [Concurrency in Swing](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/) and [Worker Threads and SwingWorker](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) for more details – MadProgrammer Sep 28 '15 at 03:43

0 Answers0