Hello,
after reading parts of the Java3D Tutorial and testing the example applet I tried to turn the whole thing into a standalone application. I dont really like the way it was suggested in the tutorial using a class which executes my applet class as an application so I simply want to make an application which uses Java3d. My problem is that with unmodified code from the example (apart from removing applet code and adding application code) nothing shows up inside my window, it just stays gray.
Basically this is my code:
public class CApplication3d {
public static void main(String[] args) {
CApplication3d app3d = new CApplication3d();
}
Canvas3D m_Canvas3d;
JFrame m_Frame;
private CApplication3d() {
m_Frame = new JFrame("A window");
m_Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
m_Frame.pack();
m_Frame.setSize(400, 300);
m_Frame.setResizable(false);
m_Frame.setVisible(true);
GraphicsConfiguration gConfig = SimpleUniverse.getPreferredConfiguration();
m_Canvas3d = new Canvas3D(gConfig);
m_Frame.getContentPane().add(m_Canvas3d);
BranchGroup scene = createSceneGraph();
scene.compile();
SimpleUniverse simpleUni = new SimpleUniverse(m_Canvas3d);
simpleUni.getViewingPlatform().setNominalViewingTransform();
simpleUni.addBranchGraph(scene);
}
private BranchGroup createSceneGraph() {
BranchGroup branchgrp = new BranchGroup();
branchgrp.addChild(new ColorCube(0.4));
return branchgrp;
}
}
(Sorry for posting a whole site of code but I failed describing what I’m doing with less text…)
I guess there is something the Applet class did what I forgot to include in my app.
I already searched sun’s java forum, this one, tried to find a simple Java3d app which is not an applet with google but wasnt able to find anything solving my problem.