Java 怎么使用canvas 3D

2019年7月29日20:03:19Java 怎么使用canvas 3D已关闭评论 382 978字阅读3分15秒

1.简介

Java 怎么使用canvas 3D?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import java.awt.GraphicsConfiguration;
import java.awt.BorderLayout;
import java.awt.Label;
import java.applet.Applet;
import com.sun.j3d.utils.applet.MainFrame;

public class CanvasDemo extends Applet {

    public CanvasDemo() {

        setLayout(new BorderLayout());

        GraphicsConfiguration config =

        SimpleUniverse.getPreferredConfiguration();

        Canvas3D canvas = new Canvas3D(config);

        add("North", new Label("This is the top"));

        add("Center", canvas);

        add("South", new Label("This is the bottom"));

        BranchGroup contents = new BranchGroup();

        contents.addChild(new ColorCube(0.3));

        SimpleUniverse universe = new SimpleUniverse(canvas);

        universe.getViewingPlatform().setNominalViewingTransform();

        universe.addBranchGraph(contents);

    }

    public static void main(String[] args) {

        CanvasDemo demo = new CanvasDemo();

        new MainFrame(demo, 400, 400);

    }

}

 
继续阅读
编程十万个怎么办