PyJ2D: Python-Java2D Applet

PyJ2D is a module designed with the intent to allow scripts coded in Python programming language and the Pygame module to run in the Java virtual machine (JVM). Python programs can run in the JVM using Jython, a Java-encoded Python interpreter that includes much of the standard library and can access the Java library. My projects are coded in Python and Pygame, and I hoped to be able to execute them online as an applet. However, since Pygame is a wrapper of the SDL multimedia library coded in C language, it cannot execute in the JVM. I wrote the PyJ2D module in Python code that essentially is a wrapper of several Java libraries including Java 2D graphics library, and modelled after the Pygame library to maintain Pygame statements. The following Java applet is a demo of Serpent Duel included in my Interphase Pack that is coded in Python/Pygame using the PyJ2D module:

PyJ2D Demo

Note: browser requires Java plug-in to execute

and JavaScript enabled to launch. As this is an unsigned applet, the security setting of the latest release of JVM will block your access.

Since PyJ2D module is modelled after Pygame, minimal change in Pygame statements would be needed, though currently the module only supports a subset of Pygame. The script can run as an applet in a browser with the Java plug-in. Alternatively, the script can be run in Java runtime on the desktop, and although untested it should be compatible with Java Web Start. It worked in the JVM with version 2.2.1 and 2.5.2 of Jython, but at this time an applet can only worked with Jython 2.2.1. This is due to the fact that the compilation step of the Python code to Java class necessary for applet deployment is not yet available in the current version of Jython, but when included the applet will benefit from Jython 2.5.2 increased Python capability and performance. The PyJ2D module is available on the PyJ2D project page.

Submitted by Jim on November 21, 2011 at 3:00 pm

This entry was posted in Programming and tagged , , , , . Bookmark the permalink. Trackbacks are closed, but you can post a comment.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>