Problem by  runing Applet

Hi,

Ich habe mich an einem Beispielapplet zur Rotation eines Farbwüürfels um 2 Achsen probiert. Compilieren und Builden ging ohne Probleme, allerdings wird mir das Applet nicht richtig aufgebaut. Es wird nur gemeldet, dass das applet gestartet wurde.

Der Code sieht wie folgt aus:

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.
;
import javax.media.j3d.;
import javax.vecmath.
;

public class HelloUniverse4 extends Applet {

private SimpleUniverse u = null;

public BranchGroup createSceneGraph() {
    BranchGroup objRoot = new BranchGroup();

//rotate object has composite transformation matrix
Transform3D rotate =new Transform3D();
Transform3D tempRotate =new Transform3D();

rotate.rotX(Math.PI/4.0d);
tempRotate.rotY(Math.PI/5.0d);
rotate.mul(tempRotate);

TransformGroup objRotate =new TransformGroup(rotate);

//Create the transform group node and initialize it to the
//identity.Enable the TRANSFORM_WRITE capability so that
//our behavior code can modify it at runtime.Add it to the
//root of the subgraph.
TransformGroup objSpin =new TransformGroup();
objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

objRoot.addChild(objRotate);
objRotate.addChild(objSpin);

//Create a simple shape leaf node,add it to the scene graph.
//ColorCube is a Convenience Utility class
objSpin.addChild(new ColorCube(0.4));

//Create a new Behavior object that performs the desired
//operation on the specified transform object and add it into
//the scene graph.
Transform3D yAxis =new Transform3D();
Alpha rotationAlpha =new Alpha(-1,4000);

RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha,objSpin,yAxis,
0.0f,(float)Math.PI*2.0f);

//a bounding sphere specifies a region a behavior is active
//create a sphere centered at the origin with radius of 1
BoundingSphere bounds =new BoundingSphere();
rotator.setSchedulingBounds(bounds);
objSpin.addChild(rotator);

return objRoot;
}
}
//end of createSceneGraph method of HelloJava3Dd

Gruss
Ruprecht

Hi,

sorry I have posted my message before I’ve seen that it was an english webforum. OK here the english translation. The Code in my first posting is the axample for rotatiing a ColorCube araound two axis. The Compiling and Building acts without any problem. On Running the applet I get only a statusline-message that the applet is starting.

What can be the problem that the cube will not be displayeed and I can’t see any rotation.

Regards,
Ruprecht

Maybe you’re running it with another jvm than you compiled the test with. IE’s build in jvm is old and specifically cannot run java3d apps. Try running your test in the appletviewer included with the java sdk.

  • elias

Hi Elias,

thanks for the quick answer.
I tried the following with this result

linux:/usr/java/j2sdk1.4.0_02/bin # ./appletviewer HelloUniverse4.html
Xlib: connection to “:0.0” refused by server
Xlib: Client is not authorized to connect to Server
Exception in thread “main” java.lang.InternalError: Can’t connect to X11 window server using ‘:0.0’ as the value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:126)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:130)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:62)
at java.awt.Window.init(Window.java:223)
at java.awt.Window.(Window.java:267)
at java.awt.Frame.(Frame.java:398)
at java.awt.Frame.(Frame.java:363)
at sun.applet.AppletViewer.(AppletViewer.java:139)
at sun.applet.StdAppletViewerFactory.createAppletViewer(AppletViewer.java:80)
at sun.applet.AppletViewer.parse(AppletViewer.java:1062)
at sun.applet.AppletViewer.parse(AppletViewer.java:996)
at sun.applet.Main.run(Main.java:138)
at sun.applet.Main.main(Main.java:80)

Regards,
ruprecht

Did you run it with the same user that you logged into X with? Specifically, running a graphical program as another user in SuSE requires you to use sux, not the ordinary su.

  • elias

Hi Elias,

you are right my first test was with the same user logged into X.
By using the sux-command the command gives no errormessage but I couldn’t get an applet. Running it under netscape it have trouble in initiate the applet. Here messages with sendingcommands are displayed. The problems with netscape are in all j3d-codes. The sun examples executed within the netbeans-ide were executed correctly (HelloUniverse, 3D-Text, mouseturnable polygon).

Regards,
Ruprecht

Hi Elias,

you are right my first test was with the same user logged into X.
By using the sux-command the command gives no errormessage but I couldn’t get an applet. Running it under netscape it have trouble in initiate the applet. Here messages with sendingcommands are displayed. The problems with netscape are in all j3d-codes. The sun examples executed within the netbeans-ide were executed correctly (HelloUniverse, 3D-Text, mouseturnable polygon).

Regards,
Ruprecht

hmm, shouldn’t an applet class have a init() or destroy() or something? It seems to me your example code is never called.

  • elias

What happens if you allow full external access to the X server first? (do an “xhost +” as the owner of the X server)

OK I tried xhost + .
The result I get no errormessage(s) but I become no output. Elias could have been right in this sentence that the code is not a normal applet. I have heard that j3d works with applets to output the result.
In the case of E. I don’t understand why in the public line you write extends applet.

The whole sourcecode of my script I posted in the german posting (beginn of thread). What can be that I get no result is that the
returncommand is written in this form

return objRoot; and not return(objRoot);

Regards,
Ruprecht

The way I look at it you only have a createSceneGraph method, but noone’s is calling it. Instead, you should be calling it from the init() that you can override from the Applet base class. That method is called from the browser when your applet is shown.

  • elias

Hi Elias,

thank you for the quick answer. You are right I missed this part. Now it is shown in my ide. Only one question I do have.
How can I build a continous rotation around the x-axis. The interpolator by default turns around the y-axis.

Regards,
Ruprecht