Advertisement

[java] Java3D and applets

Started by March 08, 2001 06:44 AM
2 comments, last by silencer 23 years, 10 months ago
I am trying to have a Java3D scene rendered in full-screen mode, so I put my Canvas3D object in a Window that is the same height and width than the screen. Unfortunately, Java3D seems to work only within an applet. It would be reason why they have implemented the MainFrame class to include an Appplet in a Frame so it becomes runnable as any application. Does anyone know something about this ? Almost every example I have seen so far is done by extending an applet and then creating a MainFrame object. All but one. Recently I have seen an example where this is just a Frame and not an Applet (and it works). This example comes from the Raw Java3D tutorial on http://www.j3d.org (chapter 1 I think). It''s called j3dAWTexample.java or so. Good, but I can''t figure out where is the problem. Even if I try to transform the HelloUniverse example as a Frame, I doesn''t work. The frame stays empty. Please help. Oh and by the way I think that using java3D could improve even 2D animation performance (as it done for some isometric games with Direct3D). Has anyone tried this ?
Java3D will run in an application. I don''t know why Sun likes showing sample code using applets.

Post your HelloUniverse code.

[<><]
Advertisement
It works !
Sorry guys, it was in fact my testing of the latest detonator 10.50 that was causing trouble with Java3D. I still don''t know why it was ok with applets but... now it works fine.
Anyway I agree with you tunabox, I can''t understand why people at Sun always use applets for their examples.
In fact, it doesn''t at all. Even with the correct drivers.
And I have tried every Java3D release I had (1.1, 1.2, 1.2.1 etc).
Here is the code of the HelloUniverse code example that I just transformed in a Frame to see (so no Applet or MainFrame here).

import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class HelloUniverse extends Frame
{
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
objRoot.addChild(new ColorCube(0.4));
objRoot.compile();
return objRoot;
}

public HelloUniverse() {
super("HelloUniverse");
setSize(300,300);
setVisible(true);
setLayout(new BorderLayout());
Canvas3D c = new Canvas3D(null);
add("Center", c);
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}

public static void main(String[] args) {
new HelloUniverse();
}
}

It compiles. But when it runs, there''s nothing in the Frame. I mean, it doesn''t actually add the Canvas3D to the content of the Frame. The Frame stays white. But if I try with -verbose option, I can see some exception raised (IllegalComponentStateException or something).

This topic is closed to new replies.

Advertisement