jME application as an applet

Hello!



Has anyone succeed to run jME applicaion in an applet?

I tried 3 approaches:



1)

http://www.jmonkeyengine.com/wiki/doku.php/writing_a_jme_applet

but application can't see native libraries which are in linux_natives.jar



2)

using LWJGL AppletLoader

I've got hangs described above:

http://www.jmonkeyengine.com/forum/index.php?topic=13957.0

but rewriting SimpleJMEApplet to SimpleApplet doesn't help



3)

using Applet-launcher https://applet-launcher.dev.java.net/

My applet can't validate native libraries.



Can you give me a link to the working example?

I haven't got any experience with jME in applets, but have you considered using Java Web Start(JLNPs) instead?

Yes, but I would like to embed my application in HTML site.

matt_z said:

Yes, but I would like to embed my application in HTML site.


i found http://www.jmonkeyengine.com/applet/ but it runs with jME3. Is there a similar example with jME 2?

That URL doesn’t seem to exist anymore. Is there an example for this?

I have an app that extends SimpleBulletApplication, which extends Application, and I want to make an applet out of it.

Theres an example class in the jme3test directory.

I remember there was alot of trouble for me getting jme2 running as an applet, although i managed in the end. I’ll see if i can dig something up this weekend.



/Rickard

I’m just now getting back to working on my project.



I looked at the LWJGL site for some of their examples, and it appears as though they don’t have any tutorials on how to launch an applet from Eclipse. I still get this error:

Code:
Exception in thread "Thread-4" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1709) at java.lang.Runtime.loadLibrary0(Runtime.java:823) at java.lang.System.loadLibrary(System.java:1030) at org.lwjgl.Sys$1.run(Sys.java:72) at java.security.AccessController.doPrivileged(Native Method) at org.lwjgl.Sys.doLoadLibrary(Sys.java:65) at org.lwjgl.Sys.loadLibrary(Sys.java:81) at org.lwjgl.Sys.(Sys.java:98) at org.lwjgl.opengl.Display.(Display.java:128) at RunApplet2$1.run(RunApplet2.java:36)
With this code:
[java]
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
import com.jme3.system.JmeSystem;
import java.applet.Applet;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.BorderLayout;
import java.util.concurrent.Callable;
import javax.swing.SwingUtilities;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;

public class RunApplet extends Applet {
private static JmeCanvasContext context;
private static Application app;
Canvas canvas;
private static RunApplet applet;
Thread gameThread;

public RunApplet(){
}

public void createCanvas(String appClass){
AppSettings settings = new AppSettings(true);
settings.setWidth(640);
settings.setHeight(480);
JmeSystem.setLowPermissions(true);
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();
}
app.setSettings(settings);
app.createCanvas();
context = (JmeCanvasContext) app.getContext();
canvas = context.getCanvas();
canvas.setSize(settings.getWidth(), settings.getHeight());
}
public void startApp(){
applet.add(canvas);
app.startCanvas();
app.enqueue(new Callable() {
public Void call(){
if (app instanceof SimpleApplication){
SimpleApplication simpleApp = (SimpleApplication) app;
simpleApp.getFlyByCamera().setDragToRotate(true);
simpleApp.getInputManager().setCursorVisible(true);
}
return null;
}
});
}
public void freezeApp() {
remove(canvas);
}
public void unfreezeApp() {
add(canvas);
}
@Override
public final void update(Graphics g){
}
@Override
public void init(){
applet = this;
createCanvas("jme3test.model.shape.TestBox");
startApp();
app.setPauseOnLostFocus(false);
System.out.println("applet:init");
}
@Override
public void start(){
// context.setAutoFlushFrames(true);
System.out.println("applet:start");
}
@Override
public void stop(){
// context.setAutoFlushFrames(false);
System.out.println("applet:stop");
}
@Override
public void destroy(){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
removeAll();
System.out.println("applet:destroyStart");
}
});
app.stop(true);
System.out.println("applet:destroyEnd");
}

}

[/java]

If you run the applet in eclipse the natives won’t be loaded because it is not using LWJGL AppletLoader.

In the createCanvas() method, you can remove the line

[java]

JmeSystem.setLowPermissions(true);

[/java]

when testing in eclipse, and put it back again when using AppletLoader. It should then load the natives.

So, I need to use the LWJGL applet loader in Eclipse, but when I deploy, I need to remove the LWJGL applet loader?

No, when you run from eclipse, you’re not using the LWJGL AppletLoader. When you deploy, you have to use AppletLoader because thats the only way of loading the natives in a limited-permissions environment.

Ah, okay.

So, my original problem still stands that I can’t get an applet to run launched from Eclipse. I believe my pasted code above is exactly like what’s in the test class.

So check the Eclipse manual?

I had a similar problem in netbeans. It came down to the natives. If it’s the same problem i had, you need to: unpack the lwjgl native files into a folder. Put that folder on the classpath of the project as a virtual machine option (in netbeans: -Djava.library.path=“path”). It may or may not be necessary, but my project shows the path to “lwjgl” as well. ( I tried alot of things).



On a side note; using the win 64 natives that came with the latest downloaded package from lwjgl did not work, and gave me an exception (related to “getPointer”) when launching. Unpacking the natives in the jme bundle worked, however.

The exception was the same as is documented here: http://slick.javaunlimited.net/viewtopic.php?t=2774&sid=089927248b2ac44a6f3f64b94eb96076 .

michalk said:
Ah, okay.
So, my original problem still stands that I can't get an applet to run launched from Eclipse. I believe my pasted code above is exactly like what's in the test class.


You can run applets from eclipse, you just need to make sure the environment is setup correctly. That is all required jars are on the classpath and any native files that are used are extracted somewhere and pointed to.

how to basically setup lwjgl to work

1. Right Click you project and select properties.
2. Click 'Java Build Path' and choose the 'Libraries' Tab.
3. Add lwjgl.jar here, once its there, click the little arrow next to lwjgl.jar to bring drop down.
4. Click 'Native Library Location' to set it to point to the folder that contains the lwjgl native files.
5. add any other external jars your using here (jme.jar, etc).

Thats it, now you should be able to run jME applets by just running your games main applet class.

My post still stands …

If you remove the line

[java]

JmeSystem.setLowPermissions(true);

[/java]

Then it should run in eclipse. Did you try that?

I teach Java programming class and I wrote an educational 3d engine running on top of jME2 (http://env3d.sourceforge.net). Since the focus of Env3D is education, I tried to make it absolutely easy to perform certain tasks – make 3D applet is one of them.



I was successful in 3D applet creation using the appletloader approach in LWJGL. Since my class is taught using the BlueJ IDE, I wrote a BlueJ plug-in to automate the process. All my students need to do is press a button in the IDE and an applet is generated for them.



Here is an example of the applet in action running as a facebook application (http://apps.facebook.com/threedphoto).



You can checkout my code on the sourceforge svn to see how it is done. The class to look at is EnvApplet.



Hope this helps.

1 Like