Java3D applet doesn't work

I cann't run a Java3D applet in my internet browser.

Page 1 of 1

11 Replies - 5349 Views - Last Post: 29 October 2010 - 02:09 AM Rate Topic: -----

#1 Sinned  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 207
  • Joined: 13-October 10

Java3D applet doesn't work

Posted 13 October 2010 - 07:22 AM

I've create a simple Java3D example applet:
import java.awt.GridLayout;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class my3DApplet extends java.applet.Applet
{
	private static final long serialVersionUID = 1L;
	
	public my3DApplet()
	{
		setLayout(new GridLayout());
		Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
		SimpleUniverse u = new SimpleUniverse(canvas);
		
		BranchGroup objRoot = createBranchGroup();
		objRoot.addChild(new Sphere(.2f));
		
		objRoot.compile();
		u.addBranchGraph(objRoot);
		u.getViewingPlatform().setNominalViewingTransform();
		
		add(canvas);
	}
	
	public BranchGroup createBranchGroup()
	{
		final BranchGroup objRoot = new BranchGroup();
		final BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 1f);
		
		final Color3f light1Color = new Color3f(.5f, .5f, .5f);
		final Vector3f light1Direction = new Vector3f(-50.0f, -80.0f, -120.0f);
		final DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
		light1.setInfluencingBounds(bounds);
		objRoot.addChild(light1);

	    final Color3f ambient1Color = new Color3f(1f, 1f, 1f);
	    final AmbientLight ambient1LightNode = new AmbientLight(ambient1Color);
	    ambient1LightNode.setInfluencingBounds(bounds);
	    objRoot.addChild(ambient1LightNode);
		
	    return objRoot;
	}
}


When I run it in my SDK Eclipse, with add the java3D libraries (j3d-1_5_2-windows-i586) to the project and put the librarie dll files (j3dcore-d3d.dll, j3dcore-ogl.dll, j3dcore-ogl-cg.dll, j3dcore-ogl-chk.dll) in het same directory as the applet .class file.
It works in Eclipse.

But when I run in in my browser (I tried IE9/chrome/FireFox) it doesn't work.
I tried very many things to let it work.

Can someone help me, please?

Thanks,

Sinned

This post has been edited by Sinned: 13 October 2010 - 07:22 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Java3D applet doesn't work

#2 javadork  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 135
  • Joined: 21-August 10

Re: Java3D applet doesn't work

Posted 13 October 2010 - 08:53 AM

Are you receiving any error messages? How are you running it in the browser?

Using your code above, I successfully ran it in Firefox using following HTML:

<html>
<applet code = "my3DApplet.class"></applet>
</html>


Was This Post Helpful? 0
  • +
  • -

#3 Sinned  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 207
  • Joined: 13-October 10

Re: Java3D applet doesn't work

Posted 13 October 2010 - 09:19 AM

No that doesn't work too.
Then I got the error:
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/media/j3d/Bounds
	at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/media/j3d/Bounds
	at java.lang.Class.getDeclaredConstructors0(Native Method)
	at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
	at java.lang.Class.getConstructor0(Unknown Source)
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.media.j3d.Bounds
	at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 14 more
Caused by: java.io.FileNotFoundException: D:\xampplite\htdocs\java\3d\applet\javax\media\j3d\Bounds.class (The system cannot find the path specified)
	at java.io.FileInputStream.open(Native Method)
	at java.io.FileInputStream.<init>(Unknown Source)
	at java.io.FileInputStream.<init>(Unknown Source)
	at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
	at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
	at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	... 19 more
Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/media/j3d/Bounds


That can only work if you have dowloaded and installed the java3d plug-in, but I don't want to run it with the plug-in.

I've allready tried to run it with the JNLP applet-launcher, but that doesn't work too.

I know that I need to use the JNLP applet-launcher, for loading the java3D libraries for a while.
https://java3d.dev.j...FourByFour.html is a java3D applet launched with the JNLP-applet launcher.

But that doesn't work for my applets.

I think I need another JNLP-applet laucher, but I can't find one.
Was This Post Helpful? 0
  • +
  • -

#4 javadork  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 32
  • View blog
  • Posts: 135
  • Joined: 21-August 10

Re: Java3D applet doesn't work

Posted 13 October 2010 - 01:39 PM

Hmm, I'll admit I don't know much about applets, so this is probably gonna stump me. But from the error, it certainly seems to be an issue with the 3D lib. Have you tried adding a CLASSPATH environment var and adding the 3D lib to it? That's the only thing I can come up with at the moment.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java3D applet doesn't work

Posted 13 October 2010 - 05:56 PM

Applet do not have constructor(s)
When the init() method of the Applet is called the Applet object already exists

so the code inside

public my3DApplet()

will never be executed. You will have to move it into the init() method
Was This Post Helpful? 0
  • +
  • -

#6 Sinned  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 207
  • Joined: 13-October 10

Re: Java3D applet doesn't work

Posted 14 October 2010 - 06:51 AM

I moved it to the init().

Now I don't get an error, but now I only see an empty-screen.

In IE9/chrome I see only a white screen.
In FireFox I see a black screen, maybe that is the Canvas3D, but I don't see the Sphere.

(I know this is a very difficult case, I'm allready busy with it for one month)
Was This Post Helpful? 0
  • +
  • -

#7 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2873
  • View blog
  • Posts: 11,032
  • Joined: 15-July 08

Re: Java3D applet doesn't work

Posted 14 October 2010 - 05:44 PM

Can we see your new updated code? It would also be helpful to see how you are organizing the files. If it comes down to it, you may have to experiment with it.
Was This Post Helpful? 0
  • +
  • -

#8 Sinned  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 207
  • Joined: 13-October 10

Re: Java3D applet doesn't work

Posted 15 October 2010 - 07:02 AM

My new java code is:
import java.awt.GridLayout;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class my3DApplet extends java.applet.Applet
{
	private static final long serialVersionUID = 1L;
	
	public my3DApplet()
	{
		setBackground(java.awt.Color.red); // for look to how far it's loading
	}
	
	public void init()
	{
		setLayout(new GridLayout());
		setBackground(java.awt.Color.gray); // for look to how far it's loading
		Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
		SimpleUniverse u = new SimpleUniverse(canvas);
		
		BranchGroup objRoot = createBranchGroup();
		TransformGroup objTrans = new TransformGroup();
		objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		
		objTrans.addChild(new Sphere(.2f));
		
		MouseRotate mr = new MouseRotate();
		mr.setSchedulingBounds(new BoundingSphere());
		mr.setTransformGroup(objTrans);
		mr.setFactor(0.007f);
		objTrans.addChild(mr);
		
		objRoot.addChild(objTrans);
		
		objRoot.compile();
		u.addBranchGraph(objRoot);
		u.getViewingPlatform().setNominalViewingTransform();
		
		add(canvas);
	}
	
	public BranchGroup createBranchGroup()
	{
		final BranchGroup objRoot = new BranchGroup();
		final BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 1f);
		
		final Color3f light1Color = new Color3f(.5f, .5f, .5f);
		final Vector3f light1Direction = new Vector3f(-50.0f, -80.0f, -120.0f);
		final DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
		light1.setInfluencingBounds(bounds);
		objRoot.addChild(light1);

	    final Color3f ambient1Color = new Color3f(1f, 1f, 1f);
	    final AmbientLight ambient1LightNode = new AmbientLight(ambient1Color);
	    ambient1LightNode.setInfluencingBounds(bounds);
	    objRoot.addChild(ambient1LightNode);
		
		return objRoot;
	}

}

Was This Post Helpful? 0
  • +
  • -

#9 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2873
  • View blog
  • Posts: 11,032
  • Joined: 15-July 08

Re: Java3D applet doesn't work

Posted 15 October 2010 - 12:24 PM

you should not have a constructor in an applet. Put it in the init() method.
Was This Post Helpful? 0
  • +
  • -

#10 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java3D applet doesn't work

Posted 15 October 2010 - 08:26 PM

View PostDogstopper, on 15 October 2010 - 01:24 PM, said:

you should not have a constructor in an applet. Put it in the init() method.

According to post #8 this should have already been done :)
But your are right there is still a useless never invoked constructor in that code
Was This Post Helpful? 0
  • +
  • -

#11 Sinned  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 207
  • Joined: 13-October 10

Re: Java3D applet doesn't work

Posted 16 October 2010 - 12:50 AM

I thought a applet ALLWAYS call first the constructor, then the init() then start().

And with closing the applet first stop() and then destroy().
Was This Post Helpful? 0
  • +
  • -

#12 Sinned  Icon User is offline

  • D.I.C Head

Reputation: 18
  • View blog
  • Posts: 207
  • Joined: 13-October 10

Re: Java3D applet doesn't work

Posted 29 October 2010 - 02:09 AM

Can anyone help me?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1