Exception in thread "main" java.lang.ClassCastException: org.j3d.aviatrix3d.output.graphics.SimpleAWTSurface cannot be cast to javax.swing.JComponent
<p>I'm trying to create a Java class that imports X3D models and displays them. And I have the X3D model called <code>test.x3d</code> saved in the Netbeans project. My code is</p>

<pre><code>import java.awt.*;
import java.util.HashMap;
import javax.swing.*;

import org.web3d.x3d.sai.*;
import org.xj3d.sai.Xj3DBrowser;

public class Xj3DSpecificDemo extends JFrame {

    public Xj3DSpecificDemo() {
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        Container contentPane = getContentPane();

        // Setup browser parameters
        HashMap requestedParameters=new HashMap();
        requestedParameters.put("Xj3D_ShowConsole",Boolean.FALSE);
        requestedParameters.put("Xj3D_FPSShown", Boolean.TRUE);

        // Create an SAI component
        X3DComponent x3dComp = BrowserFactory.createX3DComponent(requestedParameters);

        // Add the component to the UI
        JComponent x3dPanel = (JComponent)x3dComp.getImplementation();
        contentPane.add(x3dPanel, BorderLayout.CENTER);

        // Get an external browser
        ExternalBrowser x3dBrowser = x3dComp.getBrowser();

        boolean useXj3D = true;

        if (x3dBrowser.getName().indexOf("Xj3D") &lt; 0) {
            System.out.println("Not running on Xj3D, extended functions disabled");
            useXj3D = false;
        }
        setSize(500,500);
        setVisible(true);


        // Create an X3D scene by loading a file
        X3DScene mainScene = x3dBrowser.createX3DFromURL(new String[] { "test.x3d" });

        // Replace the current world with the new one
        x3dBrowser.replaceWorld(mainScene);

        if (!useXj3D)
            return;

        Xj3DBrowser xj3dBrowser = (Xj3DBrowser) x3dBrowser;
        xj3dBrowser.setMinimumFrameInterval(1000 / 15);

        boolean lines = true;

        while(true) {
            if (lines) {
                xj3dBrowser.setRenderingStyle(Xj3DBrowser.RENDER_LINES);
                lines = false;
            } else {
                xj3dBrowser.setRenderingStyle(Xj3DBrowser.RENDER_SHADED);
                lines = true;
            }

            try { Thread.sleep(250); } catch(Exception e) {}
        }

    }
    public static void main(String[] args) {

        Xj3DSpecificDemo demo = new Xj3DSpecificDemo();
    }

}
</code></pre>

<p>And the error that I'm getting is</p>

<pre><code>Exception in thread "main" java.lang.ClassCastException: org.j3d.aviatrix3d.output.graphics.SimpleAWTSurface cannot be cast to javax.swing.JComponent
    at Xj3DSpecificDemo.&lt;init&gt;(Xj3DSpecificDemo.java:44)
    at Xj3DSpecificDemo.main(Xj3DSpecificDemo.java:95)
</code></pre>

<p>But I can't seem to find the <code>aviatrix3d jar</code> anywhere to download</p>

<p><strong>EDIT</strong> </p>

<p>After downloading the <code>aviatrix3d jar</code> I get the following error</p>

<pre><code>Exception in thread "main" java.lang.ClassCastException: org.j3d.aviatrix3d.output.graphics.SimpleAWTSurface cannot be cast to javax.swing.JComponent
    at Xj3DSpecificDemo.&lt;init&gt;(Xj3DSpecificDemo.java:23)
    at Xj3DSpecificDemo.main(Xj3DSpecificDemo.java:69)
</code></pre>

<p><strong>EDIT#2</strong></p>

<p>I've also tried it with the following code so I believe it's one of the <code>Jars</code> as I'm getting the same error</p>

<pre><code>package simplesaidemo1;

import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JComponent;
import javax.swing.JFrame;
import org.web3d.x3d.sai.*;

public class SimpleSAIDemo1 extends JFrame{
    public SimpleSAIDemo1() {
        Container contentPane = getContentPane();

        // Create an SAI component
        X3DComponent x3dComp = BrowserFactory.createX3DComponent(null);

        // Add the component to the UI
        JComponent x3dPanel = (JComponent)x3dComp.getImplementation();
        contentPane.add(x3dPanel, BorderLayout.CENTER);

        // Get an external browser
        ExternalBrowser x3dBrowser = x3dComp.getBrowser();

        // Create an X3D scene by loading a file
        X3DScene mainScene = x3dBrowser.createX3DFromURL(new String[] { "test.x3d" });

        // Replace the current world with the new one
        x3dBrowser.replaceWorld(mainScene);
    }
    public static void main(String[] args) {
        SimpleSAIDemo1 demo = new SimpleSAIDemo1();
    }    
}
</code></pre>

<p>The only difference is the following lines it says the error is on</p>

<pre><code>at simplesaidemo1.SimpleSAIDemo1.&lt;init&gt;(SimpleSAIDemo1.java:17)
at simplesaidemo1.SimpleSAIDemo1.main(SimpleSAIDemo1.java:30)
</code></pre>