Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AMOEBA3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SMAC
Learning Group
AMOEBA3
Commits
ae44393f
Commit
ae44393f
authored
5 years ago
by
BrunoDatoMeneses
Browse files
Options
Downloads
Patches
Plain Diff
ADD: multiUI multithread working example
parent
54bc3f7b
No related branches found
No related tags found
1 merge request
!4
Exp rein
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
AMAKFX/src/fr/irit/smac/amak/examples/randomantsMultiUi/AntsLaunchExampleMultiUI.java
+56
-8
56 additions, 8 deletions
.../examples/randomantsMultiUi/AntsLaunchExampleMultiUI.java
with
56 additions
and
8 deletions
AMAKFX/src/fr/irit/smac/amak/examples/randomantsMultiUi/AntsLaunchExampleMultiUI.java
+
56
−
8
View file @
ae44393f
...
...
@@ -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
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment