Issues with SwingCanvas Tutorial

I’m working on an app where I need to have a jMonkey canvas in a Swing GUI. There’s a tutorial on doing that in the advanced section, here: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:swing_canvas



However, I’ve had a LOT of problems with it.



First off, near the top of the tutorial there’s a link to TestCanvas.java.



There’s a lot of short code snippets, but I noticed that none of them are snippets from TestCanvas.java. They refer to a class called SwingCanvasTest which is not listed. I haven’t been able to find a copy anywhere in the documentation, and it doesn’t seem to be a part of the jmetests package either.



I’ve tried running the TestCanvas.java class alone and it doesn’t work.



It exits with these exceptions:


java.lang.ClassNotFoundException: jme3test.post.TestRenderToTexture
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at jme3test.awt.TestCanvas.createCanvas(TestCanvas.java:205)
at jme3test.awt.TestCanvas.main(TestCanvas.java:248)
Exception in thread "main" java.lang.NullPointerException
at jme3test.awt.TestCanvas.createCanvas(TestCanvas.java:215)
at jme3test.awt.TestCanvas.main(TestCanvas.java:248)
Java Result: 1


I did my best to decipher the code, and it's some of the most complicated stuff I've ever seen condensed into such a small program, all written sans-comments. I'm not sure if I should be ashamed for not immediately understanding it, or proud that I was able to figure out at least partly what it does.

The program's failure issue comes from this statement here:

[java]try{
Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass);
app = clazz.newInstance();
}catch (ClassNotFoundException ex){
ex.printStackTrace();
}catch (InstantiationException ex){
ex.printStackTrace();
}catch (IllegalAccessException ex){
ex.printStackTrace();
}[/java]

The value of appClass is "jme3test.post.TestRenderToTexture"

Basically, this statement is trying to make a new class reference named clazz and assign the already existing class jme3test.post.TestRenderToTexture to it. This doesn't work, because the class doesn't exist. ... Hmm... Aha, well I was able to finally get this darn thing to run by running (and thus compiling) jme3test.post.TestRenderToTexture so that it does exist. I suppose it normally 'would' exist just from having compiled and run the whole test program, but that won't compile since the last update I got on the SDK.

Still, the other issues continue to be a bother. I'm having a hard time figuring out what everything does, when the tutorial seems to be working from a different example.

If anybody could help to simplify or clarify the tutorial I'd appreciate it. In the mean time, I'll continue working on it and I'll post my notes here.