Skip to content
Snippets Groups Projects
Commit ae44393f authored by BrunoDatoMeneses's avatar BrunoDatoMeneses
Browse files

ADD: multiUI multithread working example

parent 54bc3f7b
No related branches found
No related tags found
1 merge request!4Exp rein
......@@ -5,6 +5,7 @@ import fr.irit.smac.amak.ui.AmasMultiUIWindow;
import fr.irit.smac.amak.ui.MainWindow;
import fr.irit.smac.amak.ui.VUIMulti;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
......@@ -34,27 +35,74 @@ public class AntsLaunchExampleMultiUI extends Application{
AmasMultiUIWindow window = new AmasMultiUIWindow("Random Ants Multi UI 1");
//AmasMultiUIWindow window2 = new AmasMultiUIWindow("Random Ants Multi UI 2");
AmasMultiUIWindow window2 = new AmasMultiUIWindow("Random Ants Multi UI 2");
WorldExampleMultiUI env = new WorldExampleMultiUI(window);
//WorldExampleMultiUI env2 = new WorldExampleMultiUI(window2);
WorldExampleMultiUI env2 = new WorldExampleMultiUI(window2);
AntHillExampleMultiUI ants = new AntHillExampleMultiUI(window, new VUIMulti("Ants VUI 1"), env);
//new AntHillExampleMultiUI(window2, VUIMulti.get("Ants VUI 2"), env2);
AntHillExampleMultiUI ants2 = new AntHillExampleMultiUI(window2, new VUIMulti("Ants VUI 2"), env2);
System.out.println(Configuration.waitForGUI);
startTask(ants, 500, 10);
startTask(ants2, 250, 30);
for(int i=0;i<10000;i++) {
ants.cycle();
}
}
public void startTask(AntHillExampleMultiUI amas, long wait, int cycles)
{
// Create a Runnable
Runnable task = new Runnable()
{
public void run()
{
runTask(amas, wait, cycles);
}
};
// Run the task in a background thread
Thread backgroundThread = new Thread(task);
// Terminate the running thread if the application exits
backgroundThread.setDaemon(true);
// Start the thread
backgroundThread.start();
}
public void runTask(AntHillExampleMultiUI amas, long wait, int cycles)
{
for(int i = 0; i < cycles; i++)
{
try
{
// Get the Status
final String status = "Processing " + i + " of " + cycles;
// Update the Label on the JavaFx Application Thread
Platform.runLater(new Runnable()
{
@Override
public void run()
{
amas.cycle();
System.out.println(status);
}
});
Thread.sleep(wait);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}
@Override
public void stop() throws Exception {
super.stop();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment