The examples present in this module are used to demonstrate JBotSim usage.
This README contains:
- Simple example: your first JBotSim example (simple code + dependency declaration);
- Submodule dependency management: an explanation of the submodule's dependencies;
- Examples list: the list of the main examples, and their explanation (TODO).
JBotSim's HelloWorld is pretty simple. We simply need to:
- declare the dependency to JBotSim,
- provide the HelloWorld class.
It is that simple!
In your build.gradle
, make sure to have declared Maven Central as a
repository:
repositories {
mavenCentral()
}
For this HelloWorld, we need the content of the jbotsim-ui-swing
artifact
(See Which artifact should I use? section to easily find out which
artifact suits your needs).
So our build.gradle
will simply declare the dependency as follows:
dependencies {
implementation "io.jbotsim:jbotsim-ui-swing:1.2.0"
}
Gradle and Maven will take care of retrieving any required dependencies.
The source code of this example is pretty straightforward. You can also download the file from here.
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();
}
}
- We simply create a
Topology
, which is the main object of JBotSim and thus contains the main information of the simulation. - We pass it to a
JViewer
, which will display the simulation elements and allow the user to interact with it. - And eventually, we start the simulation (
tp.start();
). Since we use aJViewer
, this step could also be done by the user by selecting "Start execution" in theJViewer
's contextual menu (right click anywhere).
For development purpose, the whole module currently declares project dependencies
on :lib:jbotsim-extras-common
and :lib:jbotsim-ui-swing
.
Amongst other points, this means that:
:lib:jbotsim-extras-swing
is not used;- it does not use the fat jar or Maven Central.
TODO: add specifics