标题:[求助]在Myeclipes中运行的java3d程序不明原因的错误
取消只看楼主
小魔法师
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-9-26
 问题点数:0 回复次数:0 
[求助]在Myeclipes中运行的java3d程序不明原因的错误

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)

可是我查阅了很多程序,都是这样初始化的.
哪位高手能够指点波?

搜索更多相关主题的帖子: Myeclipes 运行 
2007-09-26 22:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-173146-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.001158 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved