Embedding JBotSim's GUI in another application

JBotSim's default GUI consists of a main window (the JViewer), which contains a JTopology component. This component is responsible for most of the the actual features of the GUI.

You can directly embed the JTopology in your own application. Below is an example of application that creates its own window frame and adds the JTopology into it. A button is also added, whose effect is to create a randomly located new node (coordinate -1 means random).

import jbotsim.Topology;
import jbotsim.ui.JTopology;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class EmbeddingApp implements ActionListener{
    Topology tp = new Topology(400,300);

    public EmbeddingApp() {
        JFrame window = new JFrame("EmbeddingApp");
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        window.setLayout(new BorderLayout());
        JButton button = new JButton("Add random node");
        button.addActionListener(this);
        window.add(button,BorderLayout.PAGE_START);
        window.add(new JTopology(tp));
        window.pack();
        window.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        tp.addNode(-1,-1);
    }

    public static void main(String[] args) {
        new EmbeddingApp();
    }
}