Java Applet woes and JPythonC...When did JPythonC last work?

RICKHIGH rickhigh at aol.com
Tue Jan 4 04:36:40 EST 2000


Subj: Applet woes and JPythonC...When did JPythonC last work?
First of all, it is 2:00 AM and I am sorry if at times I don't make sense.

Assertion: JPythonC does not work for JPython version 1.1.beta4.

I checked the jitterbug and did not see this bug listed. But I vaguely remember
someone mentioning something like this before.

If there is a patch, please let me know.
If there is a way to get a hold of an older version of JPython and JPythonC
that works, please let me know.

Here is the problem.
I am having trouble running an Applet after I compile. I am using
JPython1.1beta4. 

I was having troubles porting an JPython application to a Java Applet....SO...I
compiled a real simple Applet called MyApplet with the following options.

jpythonc --deep --package com.mycompany.mypackage --jar myapplet.jar
MyApplet.py
(BTW I tried --core but it would not work.)

The above compiles the Applet okay.

However, the Applet will not run in the AppletViewer. The AppletViewer said it
could not find some class files in jpython.jar (though jpython.jar is in my
class file and the archive APPLET param-[Yes I know that the AppletViewer
ignores the archive parameter
]).
I tried putting jpython.jar in runtime ext directory. Problems changed but did
not go away---I got a NullPointer Exception (more on this later.)

Then, I tried running the Applet in Internet Explorer (IE).
IE showed that there was a security violation as follows:

at java/io/File.exists (File.java)
	at org/python/core/PySystemState.addRegistryFile (PySystemState.java:255)
	at org/python/core/PySystemState.initRegistry (PySystemState.java:235)
	at org/python/core/PySystemState.initialize (PySystemState.java:295)
	at org/python/core/Py.initProperties (Py.java:564)
	at org/python/core/Py.initProxy (Py.java:596)
	at com/mycompany/mypackage/MyApplet.<init> (MyApplet.java:167)

It looks like the class generated is trying to read the JPython registry. Which
is a bad thing for an Applet to do. :o) (Because of the security sandbox.)

Well, I figured I will run the Applet as a standalone application until there
is a patch or the final release of JPython is released end of Jan.

But I am not out of the woods yet!

So I created a real simple Java class, just to see if I could instantiate an
instance of com.mycompany.mypackage.MyApplet.

import com.mycompany.mypackage.MyApplet;

public class Test{

public static void main(String args[]){
	MyApplet applet = new MyApplet();
	System.out.println(applet.getClass().getName());

}
}

When I compile and run the above, I get the following error:

Exception in thread "main" java.lang.NullPointerException
        at java.util.Hashtable.put(Compiled Code)
        at org.python.core.Py.initProperties(Compiled Code)
        at org.python.core.Py.initProxy(Compiled Code)
        at com.mycompany.mypackage.MyApplet.<init>(MyApplet.java:170)
        at Test.main(Test.java:6)

Now it appears that the MyApplet will not even run as a standalone class. Thus,
it appears that JPythonC is not compiling classes.

I know I have compiled classes with a previous version of JPython.
And I know I have compiled Applets with a previous version of JPython.
I don't remember which version.

I checked the jitterbug and did not see this bug listed. But I vaguely remember
someone mentioning something like this before.

If there is a patch, please let me know.
If there is a way to get a hold of an older version of JPython and JPythonC
that works, please let me know.

Here is the listing for MyApplet.py module.

from java.applet import Applet
from java.awt import List

	# Define a Python class that subclasses the Applet class 
	# (java.applet.Applet)
class MyApplet (Applet):
	def __init__(self):
		self.list = List()
		self.add(self.list)
	def init(self):
		self.list.add("Init called")
	def destroy(self):
		self.list.add("Destroy called")
	def start(self):
		self.list.add("Start called")
	def stop(self):
		self.list.add("Stop called")

if __name__ == "__main__":
	from FakeBrowser import FakeBrowser
	fakeBrowser = FakeBrowser()
	fakeBrowser.addApplet(MyApplet())

FakeBrowser is just a frame that treats MyApplet like a Panel.
It's just a way to show an Applet running standalone.

--Rick Hightower

BTW I wrote a really interesting utility to run JPython applets for debugging.
The utility implements an AppletContext and an AppletStub. It builds a list of
URLs based on the archive tag and the codebase tag. Then it uses
java.net.URLClassLoader to load classes across the wire--just like a browser. 
You can specify all of the props in a properties file and then just add an
Applet to the utility--just like FakeBrowser above, but unlike fakeBrowser it
passes an AppletContext and an AppletStub to the applet. It even generates an
HTML file based on the params that you specify. It is great for debugging an
Applet written in Jpython. Of course the utility is written in JPython. Let me
know if you are interested and I will send you the utility. It is all in one
module. Again, it is great for debugging a JPython Applet or just deploying an
Applet as a standalone application.




More information about the Python-list mailing list