| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1183 人关注过本帖
标题:[求助]在Myeclipes中运行的java3d程序不明原因的错误
只看楼主 加入收藏
小魔法师
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-9-26
收藏
 问题点数:0 回复次数:1 
[求助]在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
johnzon2008
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-4-28
收藏
得分:0 
JAVA3D1.5出现的问题
Canvas3D c=new Canvas3D(null); 将此句改为下面的试下:
import java.awt.GraphicsConfiguration;

public 你的主类名() {
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D c=new Canvas3D(config);
add("Center",c);
BranchGroup scene=createSceneGraph();
SimpleUniverse u=new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
2008-04-29 00:02
快速回复:[求助]在Myeclipes中运行的java3d程序不明原因的错误
数据加载中...
 
   



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

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