I embed JMonkey into a JFrame, so I use startCanvas().
It works fine by the “Run Project” of NetBeans, but If I package my project into a jar file and execute it, I got an Exception:
com.jme3.system.JmeDesktopSystem initialize
Info: Running on jMonkeyEngine 3.2-stable
* Branch: HEAD
* Git Hash: 95d33e6
* Build Date: 2018-01-05
Exception in thread "jME3 Main" java.lang.NoSuchMethodError: com.jme3.system.lwjgl.LwjglAbstractDisplay.loadNatives()V
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:209)
at java.lang.Thread.run(Thread.java:748)
So I change “startCanvas()” to “start()”, it works. But I need to embed my canvas into a JFrame, what should I do?
Here is my code
package ViveReader;
import java.awt.*;
import javax.swing.*;
public class Main extends JFrame {
public static Main main = null;
public static JPanel canvasPanel = null;
public static int canvasSize[] = {1200, 900};
public static void main(String[] args) {
main = new Main();
new Play();
}
public Main() {
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.getContentPane().setBackground(Color.decode("#f5f5f5"));
this.setSize(canvasSize[0], canvasSize[1]);
this.setLocationRelativeTo(null);
this.getContentPane().setLayout(new BorderLayout());
this.setVisible(true);
this.toFront();
this.setResizable(false);
canvasPanel = new JPanel();
canvasPanel.setLayout(new BorderLayout());
this.add(canvasPanel);
}
}
and the Play class
package ViveReader;
import com.jme3.app.LostFocusBehavior;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
import java.awt.Canvas;
import java.awt.Dimension;
public class Play extends SimpleApplication {
public Canvas coreCanvas = null;
private static AppSettings appSettings = null;
public Play() {
super();
appSettings = new AppSettings(true);
appSettings.setResolution(Main.canvasSize[0], Main.canvasSize[1]);
this.setLostFocusBehavior(LostFocusBehavior.Disabled);
this.setSettings(appSettings);
this.setShowSettings(false);
JmeCanvasContext jmeCanvasContext = null;
this.createCanvas();
jmeCanvasContext = (JmeCanvasContext) this.getContext();
jmeCanvasContext.setSystemListener(this);
Dimension dim = new Dimension(Main.canvasSize[0], Main.canvasSize[1]);
jmeCanvasContext.getCanvas().setPreferredSize(dim);
Main.canvasPanel.add(jmeCanvasContext.getCanvas());
this.startCanvas(true);
Main.canvasPanel.repaint();
Main.canvasPanel.revalidate();
}
@Override
public void simpleInitApp() {
Box b = new Box(1, 1, 1); // create cube shape
Geometry geom = new Geometry("Box", b); // create cube geometry from the shape
Material mat = new Material(assetManager,"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat.setColor("Color", ColorRGBA.Blue); // set color of material to blue
geom.setMaterial(mat); // set the cube's material
rootNode.attachChild(geom);
}
@Override
public void simpleUpdate(float tpf) {
}
}
Thanks