Informatics / TAMS / Applets / Interactive Jython Console
Description
This page includes our Jython interpreter applet, a fully functional Jython interpreter in a Swing GUI. It allows you to run, edit, and debug Jython scripts directly from your web-browser. Your scripts can access the whole standard Java API, as well as user-defined classes and parts of the Jython/Python standard modules. The Jython console applet uses its own toplevel window, which is shared between all applets.

The applets below use the Jython interpreter to demonstrate our concept of an interactive script: Just double-click one of the applets below to transfer and execute the code inside the applet to the console. Once the window appears, you can start to type your own Jython commands into the command line (at the bottom of the window) and read the results and possible warnings and error messages in the log panel. You can also load, edit, and save scripts and functions via the tabbed editor panels on top of the Jython console.

NOTE: To run the applet, you must grant appropriate permissions to the applet via corresponding entries in your .java.policy file. See the explanation and example file at the bottom of this page.

applet 1
Basic Jython:


applet 2
Interactive Calculator:


applet 3
User-specified Jython Function:


applet 4
Interactive Function Plotter:


applet 5
Viewer for FIG-format Vector-Graphics:


applet 6
Interactive Audio:


applet 7
Swing GUI:


Applet Requirements
The internal workings of the Jython interpreter rely on certain operations that are not permitted for Java applets by default. Therefore, you will have to change your Java policy file to grant the following permissions to the applet, or the applet will not run. You will have to reload this page after changing your policy file. Please check your browser and JDK/JRE/Java plugin documentation for the details about the policy file location and syntax. For example, on Unix/Linux systems, the policy file is called .java.policy and located in your home directory.

First, the applet needs a PropertyPermission because the Jython interpreter initialization reads your system properties. This is fairly low risk, but exposes your user name and home directory location to the applet. Second, Jython requires a few RuntimePermissions because it relies on its own classloader - the Jython input is first compiled to Java bytecodes which are then loaded into the Java virtual machine and executed by the Java VM. Allowing classloader access is dangerous in general, but absolutely necessary in this case.

Finally, if you would like to use your own Python input scripts with the applet, you will have to grant local file access to the applet. Note that you should never grant extra permissions to applets from unknown or untrustworthy sites - you will have to decide for yourself whether running Jython is worth the extra risk.

The following template policy file shows the (minimum) permissions required to run the Jython interpreter applet. The codeBase entries grant the permissions only to applets from this server:

/* EDIT AS NECESSARY, THEN RESTART YOUR BROWSER */

/* the following could be used to grant all permissions to all applets: */
/* easy to use but not recommended... */
/* grant { */
/*  permission java.security.AllPermission; */
/*}; */


grant codeBase "http://tams-www.informatik.uni-hamburg.de/applets/-" {
  permission java.util.PropertyPermission "*", "read,write";
  permission java.lang.RuntimePermission "createClassLoader";
  permission java.lang.RuntimePermission "getClassLoader";
  permission java.lang.RuntimePermission "getProtectionDomain";
  permission java.lang.RuntimePermission "accessDeclaredMembers";
  permission java.lang.RuntimePermission "queuePrintJob";
  permission java.lang.RuntimePermission "modifyThread";
  permission java.lang.RuntimePermission "setIO";
  permission javax.sound.sampled.AudioPermission "play";
  permission java.net.SocketPermission "*", "connect,accept,listen,resolve";
};


grant codeBase "http://tams-www.informatik.uni-hamburg.de/applets/-" {
  permission java.io.FilePermission "<>", "read, write, delete, execu
te";
};
07.07.2004 Impressum
http://tams-www.informatik.uni-hamburg.de/applets/jython/index.html