Using JBotSim (HelloWorld)

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.

Creating a project

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.

Declaring the dependency

Now, let us fetch JBotSim from Maven Central repository.

Maven should start retrieving the required dependencies. You are all set!

Running the example

Create a new java class

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);

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:

  1. We create a 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.).
  2. We pass it to a JViewer, which will display the simulation elements and allow the user to interact with it.
  3. Eventually, we start the simulation (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 →