From: Tom W. <to...@ss...> - 2002-02-21 18:26:17
|
Jack: > Message: 1 > From: Jack Madison <jma...@nc...> > To: jyt...@li... > Date: Wed, 20 Feb 2002 15:07:05 -0500 > Subject: [Jython-users] newbie trying to convert HelloJava3Da to jython > > 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: > 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) I think that mostly what's wrong is that you need to be using instances of the methods you reference. Unlike Java, Jython needs you to be explicit about when you're using an instance variable or method. For example, saying "setLayout(...)" doesn't imply "self"; rather, you need to explicitly say "self.setLayout(...)". Also, your add("center", canvas3D) needs to have 'center' spelled 'Center' to work, I believe: self.add("Center",...). After I changed everything (I also used instances of the variables, although that's not strictly required) in your program to reference the instance, I got a big red solid square....although I still have a hard time using "self" when I want to use "this" ;-) tom -- Tom Whittaker University of Wisconsin-Madison Space Science and Eng. Center ph: 608.262.2759 |