Skip to main content

Basic problem: two instances of the same Java3d program?

No replies
jowojofo
Offline
Joined: 2011-01-08
Points: 0

Update:
OK, I found it - restarting Windows helped. I have no idea what happened, but now it's all working fine.
Thanks anyway.

Hello,
I have got a problem which seems to me very basic - maybe I did something fundamentally wrong here, but I followed the code from some examples of how to use java3d, and I'm running out of ideas what happens. What I'm doing is: I create an AWT frame (or - same behaviour - a JFrame) and add a canvas3d to it with some little content (see listing below, a ColorBox). Everything seems to be fine as long as I'm running only a single instance of the program. But when I start a second instance (no matter whether I do it from the command line or from within Eclipse), the graphics go crazy: when I move the windows to be overlapping, the frame is painted partially in white, for example. Or, if I add an OrbitBehavior to the canvas, sometimes I make mouse movements in one of the windows, but actually the graphics in the other window change - it seems that the canvas does not know in which window it is located. Can anybody help me?

Best regards,
jowojofo

<p>import java.awt.Frame;<br />
import java.awt.GraphicsConfiguration;<br />
import java.awt.event.WindowEvent;<br />
import java.awt.event.WindowListener;<br />
<br />
import javax.media.j3d.BoundingSphere;<br />
import javax.media.j3d.BranchGroup;<br />
import javax.media.j3d.Canvas3D;<br />
import javax.vecmath.Point3d;<br />
<br />
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;<br />
import com.sun.j3d.utils.geometry.ColorCube;<br />
import com.sun.j3d.utils.universe.SimpleUniverse;<br />
<br />
<br />
public class MainFrame extends Frame {<br />
<br />
/**<br />
* @param args<br />
*/<br />
public static void main(String[] args) {<br />
MainFrame mainFrame = new MainFrame();<br />
mainFrame.setTitle(&quot;Test Frame&quot;);<br />
mainFrame.setSize(400,400);<br />
<br />
<br />
GraphicsConfiguration config = SimpleUniverse<br />
.getPreferredConfiguration();<br />
Canvas3D mainCanvas = new Canvas3D(config);<br />
<br />
SimpleUniverse universe = new SimpleUniverse(mainCanvas);<br />
BranchGroup root = new BranchGroup();<br />
root.addChild(new ColorCube(0.3));<br />
universe.getViewingPlatform().setNominalViewingTransform();<br />
<br />
OrbitBehavior behavior = new OrbitBehavior(mainCanvas, OrbitBehavior.REVERSE_TRANSLATE);<br />
BoundingSphere infiniteBounds = new BoundingSphere(new Point3d(),<br />
10000.0);<br />
behavior.setSchedulingBounds(infiniteBounds);<br />
universe.getViewingPlatform().setViewPlatformBehavior(behavior);<br />
universe.addBranchGraph(root);<br />
<br />
mainCanvas.setSize(300, 300);<br />
mainFrame.add(&quot;South&quot;, mainCanvas);<br />
mainFrame.setVisible(true);<br />
<br />
mainFrame.addWindowListener(new WindowListener() {<br />
@Override<br />
public void windowActivated(WindowEvent e) {}<br />
@Override<br />
public void windowClosed(WindowEvent e) {}<br />
<br />
@Override<br />
public void windowClosing(WindowEvent e) {<br />
System.exit(0);<br />
}<br />
<br />
@Override<br />
public void windowDeactivated(WindowEvent e) {}<br />
@Override<br />
public void windowDeiconified(WindowEvent e) {}<br />
@Override<br />
public void windowIconified(WindowEvent e) {}<br />
@Override<br />
public void windowOpened(WindowEvent e) {}<br />
});<br />
<br />
}<br />
<br />
}<br />
<br />
</p>