该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
我也出现这种问题,谁可以帮帮忙啊,这是3d的,出不来结果编译没出错
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import javax.media.j3d.AmbientLight;
import javax.media.j3d.Appearance;
import javax.media.j3d.Background;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class sphere extends Applet{
/**
*
*/
private static final long serialVersionUID = 1L;
public sphere()
{
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);
}
BranchGroup createSceneGraph()
{
BranchGroup obj = new BranchGroup();
BoundingSphere bounds = new BoundingSphere();
AmbientLight linghtA = new AmbientLight();
linghtA.setInfluencingBounds(bounds);
obj.addChild(linghtA);
Color3f color1 = new Color3f(1f,1f,1f);
Vector3f vector = new Vector3f(-.5f,0f,-2f);
DirectionalLight lightB = new DirectionalLight(color1,vector);
lightB.setInfluencingBounds( new BoundingSphere());
obj.addChild(lightB);
Transform3D transform = new Transform3D();
TransformGroup trans = new TransformGroup(transform);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
obj.addChild(trans);
Appearance app = new Appearance();
Material mat = new Material();
mat.setDiffuseColor(new Color3f(0f,0f,1f));
mat.setSpecularColor(new Color3f(1f,1f,1f));
mat.setShininess(512f);
app.setMaterial(mat);
Sphere s = new Sphere(.3f,app);
trans.addChild(s);
obj.compile();
Background bg = new Background();
bg.setColor(new Color3f(1f,1f,1f));
bg.setApplicationBounds(new BoundingSphere());
obj.addChild(bg);
return obj;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
sphere s = new sphere();
new MainFrame(s,200,200);
}
}