import java.applet.Applet;
import java.awt.BorderLayout;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Cone;
import com.sun.j3d.utils.geometry.Primitive;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.GraphicsConfiguration;
public class test extends Applet {
/**
* @param args
*/
public BranchGroup createSceneGraph(){
BranchGroup objRoot=new BranchGroup();
TransformGroup objTrans=new TransformGroup();
objRoot.addChild(objTrans);
BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
Color3f bgColor=new Color3f(0.0f,0.0f,0.0f);
Background bg=new Background(bgColor);
bg.setApplicationBounds(bounds);
objRoot.addChild(bg);
Color3f directionalColor=new Color3f(1.f,1.f,1.f);
Vector3f vec=new Vector3f(0.f,0.f,0.f);
DirectionalLight directionalLight=new DirectionalLight(directionalColor,vec);
directionalLight.setInfluencingBounds(bounds);
objRoot.addChild(directionalLight);
Appearance app=new Appearance();
Material material=new Material();
material.setDiffuseColor(new Color3f(1.0f,1.0f,1.0f));
app.setMaterial(material);
Cone cone=new Cone(.5f,1.0f,1,app);
objRoot.addChild(cone);
return objRoot;
}
public test(){
setLayout(new BorderLayout());
Canvas3D c=new Canvas3D(null);
add("center",c);
BranchGroup scene=createSceneGraph();
scene.compile();
SimpleUniverse u=new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public static void main(String[] args) {
new MainFrame(new test(),400,300);
}
}
只有"Canvas3D c=new Canvas3D(null);"这句初始化编译不过,
Exception in thread "main" java.lang.NullPointerException: Canvas3D: null GraphicsConfiguration
at javax.media.j3d.Canvas3D.checkForValidGraphicsConfig(Canvas3D.java:963)
at javax.media.j3d.Canvas3D.<init>(Canvas3D.java:1006)
at com.java3d.test.<init>(test.java:56)
at com.java3d.test.main(test.java:68)
可是我查阅了很多程序,都是这样初始化的.
哪位高手能够指点波?