From: Jack M. <jma...@nc...> - 2002-02-20 20:07:39
|
LIke the subject says, I'm new to jython AND java3D and I'm trying to get HelloJava3Da.java to run as jython code. In fact, I'm still very new to python. Basically I want to start playing around with jython using the java3d api so I started with a java example that compiles and opens a black window with a red square: ---------begin---------- import java.applet.Applet; import java.awt.BorderLayout; import java.awt.Frame; import java.awt.event.*; import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.ColorCube; import javax.media.j3d.*; import javax.vecmath.*; public class HelloJava3Da extends Applet { public HelloJava3Da() { setLayout(new BorderLayout()); Canvas3D canvas3D = new Canvas3D(null); add("Center", canvas3D); BranchGroup scene = createSceneGraph(); SimpleUniverse simpleU = new SimpleUniverse(canvas3D); simpleU.getViewingPlatform().setNominalViewingTransform(); simpleU.addBranchGraph(scene); } public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); objRoot.addChild(new ColorCube(0.4)); return objRoot; } public static void main(String[] args) { Frame frame = new MainFrame(new HelloJava3Da(), 256, 256); } } ---------end---------- This works just fine. The most current version of my attempt at a conversion to jython looks like this: ---------begin---------- from java.applet import Applet from java.awt import BorderLayout from java.awt import Frame from java.awt.event import * from com.sun.j3d.utils.applet import MainFrame from com.sun.j3d.utils.universe import * from com.sun.j3d.utils.geometry import ColorCube from javax.media.j3d import * from javax.vecmath import * class HelloJava3Da(Applet): def __init__(self): # setLayout(BorderLayout()) canvas3D = Canvas3D(None) # add("center", canvas3D) myscene = self.createSceneGraph() simpleU = SimpleUniverse(canvas3D) simpleU.getViewingPlatform().setNominalViewingTransform() simpleU.addBranchGraph(myscene) def createSceneGraph(self): objRoot = BranchGroup() objRoot.addChild(ColorCube(0.4)) return objRoot myhj = HelloJava3Da() frame = MainFrame(myhj, 256, 256) ---------end---------- It actually runs without error and opens a window, but it is blank, not black with a big red square. Notice the two lines that are commented out. When I comment out the equivalent lines from the java program, I also get a blank window that looks the same. The problem is when I uncomment the setLayout line I get: Traceback (innermost last): File "HelloJava3a.py", line 26, in ? File "HelloJava3a.py", line 13, in __init__ NameError: setLayout and when I uncomment the add line I get: WARNING: Canvas3D constructed with a null GraphicsConfiguration. Loading required GL library /usr/X11R6/lib/libGL.so.1.2.030402 Traceback (innermost last): File "HelloJava3a.py", line 26, in ? File "HelloJava3a.py", line 15, in __init__ NameError: add I get the "WARNING" and the "Loading" line when the java program runs correctly. I've tried changing around the import statements, and tried things like changing setLayout to java.awt.setLayout which doesn't work. Telling me what is wrong would be great, but I'm really hoping someone can give me a short explaination of WHY it isn't working and what I should do to get it to work. Thanks for any help you can give, -Jack |