请教!Java3D中的图形报错,请大侠帮我看看!!!!!

时间:2022-02-28 08:47:28
我的原代码如下:
package javaapp;

import java.applet.Applet;
import java.awt.BorderLayout;
import com.sun.j3d.utils.applet.JMainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class MainFrame extends javax.swing.JFrame {
    
    public BranchGroup createSceneGraph()
    {
       BranchGroup objRoot=new BranchGroup();
       float vert[]={0.8f,0.8f,0.0f,-0.8f,0.8f,0.0f,0.5f,0.0f,0.0f,-0.5f,0.0f,0.0f,-0.8f,-0.8f,0.0f,0.8f,-0.8f,0.0f};
       float color[]={0.0f,0.5f,1.0f,0.5f,0.0f,1.0f,0.0f,0.8f,0.2f,1.0f,0.0f,0.3f,0.0f,1.0f,0.3f,0.3f,0.8f,0.0f};
       Shape3D shape=new Shape3D();
       PointArray point=new PointArray(6,PointArray.COORDINATES|PointArray.COLOR_3);
       point.setCoordinate(0,vert);
       point.setColor(0,color);
       shape.setGeometry(point);
       objRoot.addChild(shape);
       objRoot.compile();
       return objRoot;
    }
    public MainFrame() {
        Canvas3D c=new Canvas3D(null);
        this.add("Center",c);
        BranchGroup scene=createSceneGraph();
        SimpleUniverse u=new SimpleUniverse(c);
        u.getViewingPlatform().setNominalViewingTransform();
        u.addBranchGraph(scene);
       
        initComponents();
    }
    
    
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        pack();
    }
    
    
    // 变量声明 - 不进行修改
    // 变量声明结束
    
}
错误如下(在运行时才报的):

************************************************************************
*** ERROR: Canvas3D constructed with a null GraphicsConfiguration
*** This will cause a NullPointerException in a subsequent release
************************************************************************


程序可以执行,但结果全是黑屏,什么效果都没有!

2 个解决方案

#1


主项目文件如下:
/*
 * Main.java
 *
 * Created on 2005年5月31日, 下午9:45
 */

package javaapp;
/**
 *
 * @author Administrator
 */
public class Main  {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               MainFrame MFrame=new MainFrame();
               MFrame.setSize(500, 300);
               MFrame.setVisible(true);
                 
            }
        });
    }
    
}

#2


汉没研究过java 3d,帮顶吧。

#1


主项目文件如下:
/*
 * Main.java
 *
 * Created on 2005年5月31日, 下午9:45
 */

package javaapp;
/**
 *
 * @author Administrator
 */
public class Main  {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
               MainFrame MFrame=new MainFrame();
               MFrame.setSize(500, 300);
               MFrame.setVisible(true);
                 
            }
        });
    }
    
}

#2


汉没研究过java 3d,帮顶吧。