This tutorial explains how to configure your project to run a minimal example using JBotSim.
We assume that you are using IntelliJ IDEA. (Other IDEs offer analogous features.)
Note: if you have troubles locating a Java SDK with a fresh IDEA install, you might want to have a look here.
You can create a basic Java project as follows
File
> New
> Project...
Select Java
, then click Next
(twice). Give a name to your project, and finally click Finish
.
Now, let us fetch JBotSim from Maven Central repository.
File
> Project Structure
Libraries
in the left panel+
From Maven ...
.io.jbotsim:jbotsim-all:1.2.0
JavaDocs
optionOK
.Maven should start retrieving the required dependencies. You are all set!
Create a new java class
src
, then New
> Java Class
HelloWorld
import io.jbotsim.core.Topology;
import io.jbotsim.ui.JViewer;
public class HelloWorld{
public static void main(String[] args){
Topology tp = new Topology();
new JViewer(tp);
tp.start();
}
}
Now, right-click anywhere in the code panel, and select Run 'HelloWorld.main()'
. You should see an empty
window in which you can add new nodes (left click), delete them (right click), or move them around (drag & drop).
In this basic example:
Topology
, which is the main object of JBotSim.
This object centralizes information about the simulation; it also manages the nodes and links, and organizes the inner
life of the system (timing, messaging, etc.).JViewer
, which will display the simulation elements and allow the user to interact with it. tp.start();
). It is important to execute this method at the end of the main()
method.The nodes in this example are the default nodes. Now we will see how to create custom nodes →