Learn Jmonkeyengine - 9 Code Examples & CST Typing Practice Test
jMonkeyEngine (jME) is an open-source, cross-platform 3D game engine written in Java. It allows developers to create 3D games and interactive applications with full control over rendering, physics, and scene management.
View all 9 Jmonkeyengine code examples →
Learn JMONKEYENGINE with Real Code Examples
Updated Nov 24, 2025
Code Sample Descriptions
jMonkeyEngine Simple Counter Example
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapText;
public class CounterApp extends SimpleApplication {
private int count = 0;
private BitmapText counterText;
public static void main(String[] args) {
CounterApp app = new CounterApp();
app.start();
}
@Override
public void simpleInitApp() {
counterText = new BitmapText(guiFont, false);
counterText.setSize(guiFont.getCharSet().getRenderedSize());
counterText.setText("Count: " + count);
counterText.setLocalTranslation(300, counterText.getLineHeight(), 0);
guiNode.attachChild(counterText);
}
@Override
public void simpleUpdate(float tpf) {
count++;
counterText.setText("Count: " + count);
}
}
A minimal jMonkeyEngine application displaying a counter in a 3D scene and updating it each frame.
jMonkeyEngine Moving Box Example
import com.jme3.app.SimpleApplication;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
public class MovingBoxApp extends SimpleApplication {
private Geometry box;
public static void main(String[] args) {
new MovingBoxApp().start();
}
@Override
public void simpleInitApp() {
Box b = new Box(1,1,1);
box = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
box.setMaterial(mat);
rootNode.attachChild(box);
}
@Override
public void simpleUpdate(float tpf) {
box.move(0, 0, 1 * tpf);
}
}
A simple box moving forward in the 3D scene.
jMonkeyEngine Rotating Cube Example
import com.jme3.app.SimpleApplication;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
public class RotatingCubeApp extends SimpleApplication {
private Geometry cube;
public static void main(String[] args) {
new RotatingCubeApp().start();
}
@Override
public void simpleInitApp() {
Box b = new Box(1,1,1);
cube = new Geometry("Cube", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Red);
cube.setMaterial(mat);
rootNode.attachChild(cube);
}
@Override
public void simpleUpdate(float tpf) {
cube.rotate(0, 1 * tpf, 0);
}
}
Rotates a cube around the Y axis every frame.
jMonkeyEngine Jumping Sphere Example
import com.jme3.app.SimpleApplication;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Sphere;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
public class JumpingSphereApp extends SimpleApplication {
private Geometry sphere;
private float vy = 0;
private float y = 1;
private float gravity = -9.8f;
public static void main(String[] args) {
new JumpingSphereApp().start();
}
@Override
public void simpleInitApp() {
Sphere s = new Sphere(16,16,1);
sphere = new Geometry("Sphere", s);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Green);
sphere.setMaterial(mat);
sphere.setLocalTranslation(0,y,0);
rootNode.attachChild(sphere);
}
@Override
public void simpleUpdate(float tpf) {
vy += gravity * tpf;
y += vy * tpf;
if (y < 1) { y = 1; vy = 5; } // bounce
sphere.setLocalTranslation(0, y, 0);
}
}
A sphere jumps up and falls down simulating gravity.
jMonkeyEngine Camera Follow Example
import com.jme3.app.SimpleApplication;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
public class CameraFollowApp extends SimpleApplication {
private Geometry box;
public static void main(String[] args) {
new CameraFollowApp().start();
}
@Override
public void simpleInitApp() {
Box b = new Box(1,1,1);
box = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Yellow);
box.setMaterial(mat);
rootNode.attachChild(box);
}
@Override
public void simpleUpdate(float tpf) {
box.move(1 * tpf, 0, 0);
cam.setLocation(box.getLocalTranslation().add(0,5,10));
cam.lookAt(box.getLocalTranslation(), Vector3f.UNIT_Y);
}
}
Camera follows a moving object.
jMonkeyEngine Color Changing Box
import com.jme3.app.SimpleApplication;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
public class ColorBoxApp extends SimpleApplication {
private Geometry box;
private float time = 0;
public static void main(String[] args) {
new ColorBoxApp().start();
}
@Override
public void simpleInitApp() {
Box b = new Box(1,1,1);
box = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
box.setMaterial(mat);
rootNode.attachChild(box);
}
@Override
public void simpleUpdate(float tpf) {
time += tpf;
box.getMaterial().setColor("Color", new ColorRGBA((float)Math.abs(Math.sin(time)), 0, 1-(float)Math.abs(Math.sin(time)), 1));
}
}
Box changes color every frame.
jMonkeyEngine Spinning Torus
import com.jme3.app.SimpleApplication;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Torus;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
public class SpinningTorusApp extends SimpleApplication {
private Geometry torus;
public static void main(String[] args) {
new SpinningTorusApp().start();
}
@Override
public void simpleInitApp() {
Torus t = new Torus(16,16,1,2);
torus = new Geometry("Torus", t);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Cyan);
torus.setMaterial(mat);
rootNode.attachChild(torus);
}
@Override
public void simpleUpdate(float tpf) {
torus.rotate(tpf, tpf, 0);
}
}
A torus spinning along multiple axes.
jMonkeyEngine Physics Falling Box
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
public class FallingBoxApp extends SimpleApplication {
private BulletAppState bulletAppState;
public static void main(String[] args) {
new FallingBoxApp().start();
}
@Override
public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
Box b = new Box(1,1,1);
Geometry box = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Magenta);
box.setMaterial(mat);
box.addControl(new RigidBodyControl(1f));
rootNode.attachChild(box);
bulletAppState.getPhysicsSpace().add(box);
}
}
Box falls under gravity using Bullet physics.
jMonkeyEngine Orbit Camera Example
import com.jme3.app.SimpleApplication;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Sphere;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
public class OrbitCameraApp extends SimpleApplication {
private float angle = 0;
public static void main(String[] args) {
new OrbitCameraApp().start();
}
@Override
public void simpleInitApp() {
Sphere s = new Sphere(16,16,1);
Geometry sphere = new Geometry("Sphere", s);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.White);
sphere.setMaterial(mat);
rootNode.attachChild(sphere);
}
@Override
public void simpleUpdate(float tpf) {
angle += tpf;
cam.setLocation(new Vector3f(10 * (float)Math.cos(angle), 5, 10 * (float)Math.sin(angle)));
cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);
}
}
Camera orbits around a central object.
Frequently Asked Questions about Jmonkeyengine
What is Jmonkeyengine?
jMonkeyEngine (jME) is an open-source, cross-platform 3D game engine written in Java. It allows developers to create 3D games and interactive applications with full control over rendering, physics, and scene management.
What are the primary use cases for Jmonkeyengine?
3D PC games. Android 3D games. Educational simulations. Virtual reality prototypes. Interactive 3D visualizations
What are the strengths of Jmonkeyengine?
Full-featured 3D engine in Java. Open-source and free. Integrated physics and shader support. Active developer community. Cross-platform for desktop and mobile
What are the limitations of Jmonkeyengine?
Primarily 3D; 2D support is minimal. Requires good understanding of Java and OOP. No visual editor included by default (SceneComposer optional). Smaller asset marketplace than Unity or Unreal. Limited built-in networking; third-party needed for multiplayer
How can I practice Jmonkeyengine typing speed?
CodeSpeedTest offers 9+ real Jmonkeyengine code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.