multiple instances of Netlogo GUI controlled by Java

23 views
Skip to first unread message

sidonie derenoncourt

unread,
Sep 25, 2019, 9:07:29 AM9/25/19
to netlogo-devel

Hello,

I used to control a Netlogo instance with GUI from Java.
But now I would like to control 2 instances (with GUI) from one Java program.

Is it possible ? How can I do ?

Thanks a lot

Jeremy Baker

unread,
Oct 1, 2019, 1:36:00 PM10/1/19
to netlogo-devel
Sidonie,

It is possible to run two NetLogo instances with the GUI at the same time, but it's unfortunately a little complicated.  Because the `App.app` entry point that you'd usually use to startup the GUI is a static variable, it's not as simple as calling `App.app.open()` twice, since you'd just overwrite the first model with the second.

One option would be to investigate launching separate processes to run each NetLogo GUI.  If you start a wholly separate process with a different JVM class loader, each will get its own static variables, so you can then run your models through the normal `App.app.open()` method.  You then have to deal with the complexity of managing separate processes, though.

Another option might be to look at how the LevelSpace extension runs separate models.  It looks like it runs all models through headless workspaces (which are easy to setup multiple instances of), but LevelSpace can also display a GUI for the child models with some custom code.  This code is spread out over a few classes, but some good starting points to look at might be the `GUIChildModel` class and the `GUIPanel` class.

I hope that helps, good luck with your project.

-Jeremy

seth....@lightbend.com

unread,
Oct 1, 2019, 4:12:22 PM10/1/19
to netlogo-devel
If you want to support editing of models, you need `App` for that, and you can only have one `App` per process.

But if you're just trying let the user interact with existing models, you don't need App. org.nlogo.lite.InterfaceComponent is sufficient, and you can have multiple instances of it in a single JVM and single classloader just fine, it's designed for that. See https://github.com/NetLogo/NetLogo/wiki/Controlling-API

(Caveat: it worked in NetLogo 5, so it probably still works in 6, but I don't have firsthand experience with it on 6.)

Seth
Reply all
Reply to author
Forward
0 new messages