代码如下:
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.*;
import javax.vecmath.*;
public class MyCone extends Applet{
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,-1.0f);
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(0.5f,1.0f,1,app);
objRoot.addChild(cone);
return objRoot;
}
public MyCone(){
setLayout(new BorderLayout());
Canvas3D c = new Canvas3D();
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 MyCone(),400,300);
}
}
编译无问题,运行却出现这样的问题:
exception in thread "main" java.lang.noclassdeffouderror:MyCone(wrong name:MyCone)
at java.lang.classloader.defineclass(native method)
at java.lang.classloader.defineclass(classloader.java:620)
.......
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.*;
import javax.vecmath.*;
public class MyCone extends Applet{
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,-1.0f);
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(0.5f,1.0f,1,app);
objRoot.addChild(cone);
return objRoot;
}
public MyCone(){
setLayout(new BorderLayout());
Canvas3D c = new Canvas3D();
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 MyCone(),400,300);
}
}
编译无问题,运行却出现这样的问题:
exception in thread "main" java.lang.noclassdeffouderror:MyCone(wrong name:MyCone)
at java.lang.classloader.defineclass(native method)
at java.lang.classloader.defineclass(classloader.java:620)
.......
解决方案 »
- java调用C# webservice接口,返回XML
- swing 怎么画渐变的线
- 为什么StringBuffer的append方法比“+”高效?
- 线程池的问题。如何监控线程池中线程,比如查看正在等待中的任务个数 ....................................
- ((DefaultEditor)JSpinner.getEditor()).getTextField().requestFocusInWindow()有没有替代的方法设置它的光标位置
- JavaBean出错,我就没用成功过。急求解决
- 如果想用Iterator对List进行反复遍历,如何操作?
- 关于clone的问题
- 这个程序有多少错误呀?能不能告诉我
- 请问将货币类型数据从access数据库取出来变成双精度类型的该怎么办?将双精度类型又如何变成货币类型放进数据库呢?
- rss订阅用jsp如何实现
- 大家帮分析下这个循环结果如何得到
改成
new MainFrame((Applet)new MyCone(),400,300);
试试
具体怎么写我忘了 自己百度下~