By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

jython: how do you exit an applet early?

P: n/a
I've written an applet using Java3D for rendering, which works fine if
you have Java3D installed, of course.

What I want to do is try to import the Java3D libraries and bail with an
error message to the user if they're not there.

You can't do "raise SystemExit" or "sys.exit(0)" because both of those
try to kill the browser's Java VM, which a) raises a security exception
and b) isn't what I want anyway.

A "return" statement does the trick as an applet, but raises a
"SyntaxError: 'return' outside function" and doesn't even run when using
Jython from the command line to test things. (It shouldn't work as an
applet, but at this point I was just randomly trying things in

What SHOULD I be doing?

This is the code I'm using:

# Java3D libraries
from com.sun.j3d.utils.applet import MainFrame
from com.sun.j3d.utils.behaviors.vp import *
from com.sun.j3d.utils.image import *
from com.sun.j3d.utils.universe import *
from import *
from javax.vecmath import *
# Deal gracefully with Java3D not being installed
class GearBox(Applet):
def init(self):
self.add(Label('Java3D is not properly installed.', Label.CENTER))
if __name__ == '__main__':
# Not running as an applet
print 'Java3D is not properly installed.'
raise SystemExit
# SyntaxError: 'return' outside function
My email is gcash AT, but please post your reply to the group.

I just like saying "chlorine pentafluoride"
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.