给出Java.lang.UnsatifiedLinkError的Java 3D代码

给出Java.lang.UnsatifiedLinkError的Java 3D代码,java,eclipse,awt,java-3d,Java,Eclipse,Awt,Java 3d,我正在尝试运行以下Java3D示例代码。我指的是3个JAR和1个dll文件夹。他们的名字如下:- import java.applet.Applet; import java.awt.BorderLayout; import java.awt.Button; import java.awt.GraphicsConfiguration; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.A

我正在尝试运行以下Java3D示例代码。我指的是3个JAR和1个dll文件夹。他们的名字如下:-

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.GraphicsConfiguration;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.media.j3d.AmbientLight;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.Timer;
import javax.vecmath.Color3f;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;
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 InteractiveAnimation extends Applet implements ActionListener, KeyListener {

    private static final long serialVersionUID = 1L;

    private Button go = new Button("Go");

  private TransformGroup objTrans;

  private Transform3D trans = new Transform3D();

  private float height = 0.0f;

  private float sign = 1.0f; // going up or down

  private Timer timer;

  private float xloc = 0.0f;

  public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);

    // Create a simple shape leaf node, add it to the scene graph.
    Sphere sphere = new Sphere(0.25f);
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D pos1 = new Transform3D();
    pos1.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
    objTrans.setTransform(pos1);
    objTrans.addChild(sphere);
    objRoot.addChild(objTrans);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
        100.0);

    Color3f light1Color = new Color3f(1.0f, 0.0f, 0.2f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color,
        light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    return objRoot;
  }

  public InteractiveAnimation() {
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse
        .getPreferredConfiguration();
    Canvas3D c = new Canvas3D(config);
    add("Center", c);
    c.addKeyListener(this);
    timer = new Timer(100, this);
    //timer.start();
    Panel p = new Panel();
    p.add(go);
    add("North", p);
    go.addActionListener(this);
    go.addKeyListener(this);
    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();

    SimpleUniverse u = new SimpleUniverse(c);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(scene);
  }

  public void keyPressed(KeyEvent e) {
    //Invoked when a key has been pressed.
    if (e.getKeyChar() == 's') {
      xloc = xloc + .1f;
    }
    if (e.getKeyChar() == 'a') {
      xloc = xloc - .1f;
    }
  }

  public void keyReleased(KeyEvent e) {
    // Invoked when a key has been released.
  }

  public void keyTyped(KeyEvent e) {
    //Invoked when a key has been typed.
  }

  public void actionPerformed(ActionEvent e) {
    // start timer when button is pressed
    if (e.getSource() == go) {
      if (!timer.isRunning()) {
        timer.start();
      }
    } else {
      height += .1 * sign;
      if (Math.abs(height * 2) >= 1)
        sign = -1.0f * sign;
      if (height < -0.4f) {
        trans.setScale(new Vector3d(1.0, .8, 1.0));
      } else {
        trans.setScale(new Vector3d(1.0, 1.0, 1.0));
      }
      trans.setTranslation(new Vector3f(xloc, height, 0.0f));
      objTrans.setTransform(trans);
    }
  }

  public static void main(String[] args) {
    System.out.println("Program Started");
    InteractiveAnimation bb = new InteractiveAnimation();
    bb.addKeyListener(bb);
    MainFrame mf = new MainFrame(bb, 256, 256);
  }
}
  • vecmath.jar
  • j3d-core-1.3.1.jar
  • j3dutils.jar
  • j3dcore-ogl.dll(我还尝试引用一个jar文件而不是这个dll文件。jar文件是j3dcore-d3d_dll.jar)
  • 我还尝试将它们放在jdk和jre的bin和lib文件夹中

    我还将j3dcore-ogl.dll文件的路径添加到名为“path”的系统环境变量中。后来我尝试用j3dcore-d3d_dll.jar文件的路径替换它

    代码如下:-

    import java.applet.Applet;
    import java.awt.BorderLayout;
    import java.awt.Button;
    import java.awt.GraphicsConfiguration;
    import java.awt.Panel;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    
    import javax.media.j3d.AmbientLight;
    import javax.media.j3d.BoundingSphere;
    import javax.media.j3d.BranchGroup;
    import javax.media.j3d.Canvas3D;
    import javax.media.j3d.DirectionalLight;
    import javax.media.j3d.Transform3D;
    import javax.media.j3d.TransformGroup;
    import javax.swing.Timer;
    import javax.vecmath.Color3f;
    import javax.vecmath.Point3d;
    import javax.vecmath.Vector3d;
    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 InteractiveAnimation extends Applet implements ActionListener, KeyListener {
    
        private static final long serialVersionUID = 1L;
    
        private Button go = new Button("Go");
    
      private TransformGroup objTrans;
    
      private Transform3D trans = new Transform3D();
    
      private float height = 0.0f;
    
      private float sign = 1.0f; // going up or down
    
      private Timer timer;
    
      private float xloc = 0.0f;
    
      public BranchGroup createSceneGraph() {
        // Create the root of the branch graph
        BranchGroup objRoot = new BranchGroup();
        objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        objRoot.addChild(objTrans);
    
        // Create a simple shape leaf node, add it to the scene graph.
        Sphere sphere = new Sphere(0.25f);
        objTrans = new TransformGroup();
        objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        Transform3D pos1 = new Transform3D();
        pos1.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
        objTrans.setTransform(pos1);
        objTrans.addChild(sphere);
        objRoot.addChild(objTrans);
        BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0),
            100.0);
    
        Color3f light1Color = new Color3f(1.0f, 0.0f, 0.2f);
        Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
        DirectionalLight light1 = new DirectionalLight(light1Color,
            light1Direction);
        light1.setInfluencingBounds(bounds);
        objRoot.addChild(light1);
    
        // Set up the ambient light
        Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f);
        AmbientLight ambientLightNode = new AmbientLight(ambientColor);
        ambientLightNode.setInfluencingBounds(bounds);
        objRoot.addChild(ambientLightNode);
    
        return objRoot;
      }
    
      public InteractiveAnimation() {
        setLayout(new BorderLayout());
        GraphicsConfiguration config = SimpleUniverse
            .getPreferredConfiguration();
        Canvas3D c = new Canvas3D(config);
        add("Center", c);
        c.addKeyListener(this);
        timer = new Timer(100, this);
        //timer.start();
        Panel p = new Panel();
        p.add(go);
        add("North", p);
        go.addActionListener(this);
        go.addKeyListener(this);
        // Create a simple scene and attach it to the virtual universe
        BranchGroup scene = createSceneGraph();
    
        SimpleUniverse u = new SimpleUniverse(c);
        u.getViewingPlatform().setNominalViewingTransform();
        u.addBranchGraph(scene);
      }
    
      public void keyPressed(KeyEvent e) {
        //Invoked when a key has been pressed.
        if (e.getKeyChar() == 's') {
          xloc = xloc + .1f;
        }
        if (e.getKeyChar() == 'a') {
          xloc = xloc - .1f;
        }
      }
    
      public void keyReleased(KeyEvent e) {
        // Invoked when a key has been released.
      }
    
      public void keyTyped(KeyEvent e) {
        //Invoked when a key has been typed.
      }
    
      public void actionPerformed(ActionEvent e) {
        // start timer when button is pressed
        if (e.getSource() == go) {
          if (!timer.isRunning()) {
            timer.start();
          }
        } else {
          height += .1 * sign;
          if (Math.abs(height * 2) >= 1)
            sign = -1.0f * sign;
          if (height < -0.4f) {
            trans.setScale(new Vector3d(1.0, .8, 1.0));
          } else {
            trans.setScale(new Vector3d(1.0, 1.0, 1.0));
          }
          trans.setTranslation(new Vector3f(xloc, height, 0.0f));
          objTrans.setTransform(trans);
        }
      }
    
      public static void main(String[] args) {
        System.out.println("Program Started");
        InteractiveAnimation bb = new InteractiveAnimation();
        bb.addKeyListener(bb);
        MainFrame mf = new MainFrame(bb, 256, 256);
      }
    }
    
    import java.applet.applet;
    导入java.awt.BorderLayout;
    导入java.awt.Button;
    导入java.awt.GraphicsConfiguration;
    导入java.awt.Panel;
    导入java.awt.event.ActionEvent;
    导入java.awt.event.ActionListener;
    导入java.awt.event.KeyEvent;
    导入java.awt.event.KeyListener;
    导入javax.media.j3d.AmbientLight;
    导入javax.media.j3d.BoundingSphere;
    导入javax.media.j3d.BranchGroup;
    导入javax.media.j3d.Canvas3D;
    导入javax.media.j3d.DirectionalLight;
    导入javax.media.j3d.Transform3D;
    导入javax.media.j3d.TransformGroup;
    导入javax.swing.Timer;
    导入javax.vecmath.Color3f;
    导入javax.vecmath.Point3d;
    导入javax.vecmath.Vector3d;
    导入javax.vecmath.Vector3f;
    导入com.sun.j3d.utils.applet.MainFrame;
    导入com.sun.j3d.utils.geometry.Sphere;
    导入com.sun.j3d.utils.universe.SimpleUniverse;
    公共类InteractiveAnimation扩展小程序实现ActionListener、KeyListener{
    私有静态最终长serialVersionUID=1L;
    专用按钮go=新按钮(“go”);
    私有组objTrans;
    私有Transform3D trans=新Transform3D();
    专用浮子高度=0.0f;
    私人浮动符号=1.0f;//上升或下降
    私人定时器;
    私有浮点数xloc=0.0f;
    公共分支组createSceneGraph(){
    //创建分支图的根
    BranchGroup objRoot=new BranchGroup();
    objTrans=新的TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    addChild(objTrans);
    //创建一个简单的形状叶节点,将其添加到场景图中。
    球体=新球体(0.25f);
    objTrans=新的TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D pos1=新Transform3D();
    pos1.setTranslation(新向量3f(0.0f,0.0f,0.0f));
    objTrans.setTransform(pos1);
    添加子对象(球体);
    addChild(objTrans);
    BoundingSphere bounds=新的BoundingSphere(新点3D(0.0,0.0,0.0),
    100.0);
    Color3f light1Color=新的Color3f(1.0f、0.0f、0.2f);
    矢量3F light1Direction=新矢量3F(4.0f,-7.0f,-12.0f);
    方向灯光1=新方向灯光(灯光1颜色,
    光1方向);
    light1.设置影响边界(边界);
    objRoot.addChild(light1);
    //设置环境光
    Color3f ambientColor=新的Color3f(1.0f、1.0f、1.0f);
    AmbientLight ambientLightNode=新的AmbientLight(ambientColor);
    ambientLightNode.SetInfluenceBounds(边界);
    addChild(ambientLightNode);
    返回objRoot;
    }
    公共交互动画(){
    setLayout(新的BorderLayout());
    图形配置配置=SimpleUniverse
    .getPreferredConfiguration();
    Canvas3D c=新的Canvas3D(配置);
    添加(“中心”,c);
    c、 addKeyListener(此);
    定时器=新定时器(100,本);
    //timer.start();
    面板p=新面板();
    p、 加(去);
    加上(“北”,p);
    go.addActionListener(这个);
    go.addKeyListener(这个);
    //创建一个简单的场景并将其附加到虚拟世界
    BranchGroup场景=createSceneGraph();
    简单宇宙u=新的简单宇宙(c);
    u、 getViewingPlatform().setNominalViewingTransform();
    u、 添加分支图(场景);
    }
    按下公共无效键(按键事件e){
    //当按下某个键时调用。
    如果(如getKeyChar()=='s'){
    xloc=xloc+.1f;
    }
    如果(例如getKeyChar()=='a'){
    xloc=xloc-.1f;
    }
    }
    公共无效密钥已释放(密钥事件e){
    //在释放密钥时调用。
    }
    public void keyTyped(KeyEvent e){
    //在键入密钥时调用。
    }
    已执行的公共无效操作(操作事件e){
    //按下按钮时启动计时器
    如果(如getSource()==go){
    如果(!timer.isRunning()){
    timer.start();
    }
    }否则{
    高度+=.1*符号;
    如果(数学绝对值(高度*2)>=1)
    符号=-1.0f*符号;
    如果(高度<-0.4f){
    trans.setScale(新矢量3D(1.0,8,1.0));
    }否则{
    trans.setScale(新Vector3d(1.0,1.0,1.0));
    }
    trans.setTranslation(新向量3f(xloc,高度,0.0f));
    objTrans.setTransform(trans);
    }
    }
    公共静态void main(字符串[]args){
    System.out.println(“程序启动”);
    InteractiveAnimation bb=新的InteractiveAnimation();
    addKeyListener(bb);
    大型机mf=新的大型机(bb,256,256);
    }
    }
    
    执行此操作时,我会得到以下异常堆栈跟踪:-

    线程“main”java.lang.UnsatisfiedLinkError中出现异常:java.library.path中没有J3D 位于java.lang.ClassLoader.loadLibrary(未知源) 位于java.lang.Runtime.loadLibrary0(未知源) 位于java.lang.System.loadLibrary(未知源) 位于javax.media.j3d.MasterControl$22.run(MasterControl.java:889) 位于java.security.AccessController.doPrivileged(本机方法) 位于javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:886) 位于javax.media.j3d.virtualniverse。(virtualniverse.java:229) 在InteractiveAnimation上。(InteractiveAnimation.java:84) 位于InteractiveAnimation.main(InteractiveAnimation.java:143)


    我应该怎么做才能运行这个程序?

    上面的评论完全错误。Java3D1.3.1已经完全过时,不再需要在最新版本中手动处理DLL