JBotSim 1.0-beta has been released with some API changes. All examples have been updated accordingly. Please make sure you are using version 1.0 beta.

Creating a node algorithm

Node algorithms (aka distributed algorithm) are created in two steps:

  1. Create a class that extends Node
  2. Override some methods

Here is an example with four methods overridden

public class BasicNode extends Node{
    public void onStart() {
        // initialize the node variables

    public void onClock() {
        // code to be executed by this node in each round

    public void onMessage(Message message) {
        // processing of a received message

    public void onSelection() {
        // what to do when this node is selected by the user

Most algorithms can be specified using 2 or 3 such methods (others exist). You can of course add your own variables and methods.

Once your class is ready, you can tell JBotSim to use it as default node model, future nodes added to the topology will be instantiated using this class.

    public static void main(String[] args){
        Topology tp = new Topology();
        new JViewer(tp);

You can also add nodes yourself to the topology as follows:

    tp.addNode(new BasicNode());

or with coordinates:

    tp.addNode(200, 100, new BasicNode());

In general, the main() method is in a different class, but this is not necessary.