From: James S. <bit...@ph...> - 2002-02-04 12:55:08
|
Hi all, firstly, I'm a newbie to both jython and pretty much to java in general (I've done a couple jobs in java, but nothing to write home about), so my problem might just be something I'm doing wrong. I have written a small jython application which displayes a swing JTree that is dynamically loaded from a url via a WDDX (XML) packet for each node (i.e expand a node, application downloads packet, adds nodes to be shown...) . Anyway, the app worked really nicely, and it was time to turn my application into an applet (which is what I want this particular thing for), easy I thought. So I just added class wddxTreeApplet(swing.JApplet): def init(self) : getContentPane().add(swing.JScrollPane(wddxTree("Root Of Tree", "http://mortimer/ ~boffin/treeViewDumper.cfm"))) to the file wddxTreeApplet.cfm that has all the required classes in it (aside from the supporting 3rd party ones which are in a couple of jars) ran jythonc over it to produce class files, shifted the class files into an appropriate location and write a dumm html page with an applet to call it . Didn't work, the java console tells me this... java.lang.ClassCastException: wddxTreeApplet at sun.applet.AppletPanel.createApplet(AppletPanel.java:579) at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1178) at sun.applet.AppletPanel.runLoader(AppletPanel.java:515) at sun.applet.AppletPanel.run(AppletPanel.java:293) at sun.plugin.navig.motif.MotifAppletViewer.maf_run(MotifAppletViewer.java:127) at sun.plugin.navig.motif.MotifAppletViewer.run(MotifAppletViewer.java:123) at java.lang.Thread.run(Thread.java:484) Ok, so I figured I'd better check that applets are working in my browser still, head over o the jython applet demos, yep - alll still work. So, I take the code for the HelloWorld applet as on the jython applets main page (there's a missing comma in that code as displayed btw) because I know that works, put it into a jython file called testApplet.py as from java.applet import Applet class testApplet(Applet): def paint(self, g): g.drawString("Hello from Jython!", 20, 30) compile with jythonc, move classes (well, everything in jpywork directory) to approprioate place, write an html file, test it, and still doesn't work... java.lang.ClassCastException: testApplet at sun.applet.AppletPanel.createApplet(AppletPanel.java:579) at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1178) at sun.applet.AppletPanel.runLoader(AppletPanel.java:515) at sun.applet.AppletPanel.run(AppletPanel.java:293) at sun.plugin.navig.motif.MotifAppletViewer.maf_run(MotifAppletViewer.java:127) at sun.plugin.navig.motif.MotifAppletViewer.run(MotifAppletViewer.java:123) at java.lang.Thread.run(Thread.java:484) same error it seems. So what am I doing wrong ? Is it my jre/jdk (blackdown linux 1.3.1, using plugin under both mozilla and opera with same results) ? Have I missed some vital step ? BTW: jython rocks, even if I can't get my own applets working :-) --- James Sleeman |
From: Syver E. <syv...@on...> - 2002-02-05 00:36:01
|
James Sleeman <bit...@ph...> writes: > Hi all, > firstly, I'm a newbie to both jython and pretty much to java in > general (I've done a couple jobs in java, but nothing to write home > about), I can recommend you get New Riders jython book. It goes through why things like this happens really thoroughly and has been a lot of help to me, in clearing these kinds of problems and understanding why they happen. Of the top of my head I can suggest, compiling your applet with the --jar --core --deep options. Your .py file must have the same name as your class, and watch out for the message from jythonc that your python class is extending the java class, JApplet in your case. If jythonc doesn't say this you got something wrong, imports or classpath problems maybe. It's good to remember that jythonc compilation is nothing like ordinary java compilation so don't count on really basic errors being flagged just because it compiles. Be aware that you can specify more than one jar file in your applet tag. Like this: archive="jarnumberone.jar , jarnumbertwo.jar" This way you don't have to put all the files into the same jar. Alas I have heard that this doesn't work with all browsers. It works on IE 6.0 which is what I have tested with. > so my problem might just be something I'm doing wrong. Probably yes. The class cast exception in your traceback indicates that your jython class doesn't extend the class you think it extends see above. Hope this helps. -- Vennlig hilsen Syver Enstad |
From: James S. <bit...@ph...> - 2002-02-05 02:48:45
|
Syver Enstad <syv...@on...> wrote on 2/5/2002 1:34:50 PM: >I can recommend you get New Riders jython book. It goes through why >things like this happens really thoroughly and has been a lot of help to >me, in clearing these kinds of problems and understanding why they happen. I'll look it up, of course getting it in New Zealand might be a challenge (always Amazon I guess) :-) >Of the top of my head I can suggest, compiling your applet with the >--jar --core --deep options. Hmm, I thought I had tried jaring the small hello-world applet, just tried again and it worked (at least here at work on win2k, but should work at home as well, I'm using the same plugin version). So, I know that I can compile working applets :-) >Your .py file must have the same name as >your class, and watch out for the message from jythonc that your >python class is extending the java class, JApplet in your case. Ok, I think this is where I am going wrong. The file i want to compile, wddxTreeApplet.py has four top level classes in it - wddxNode (which extends swing.tree.DefaultMutableTreeNode), wddxTreeModel (extending swing.tree.DefaultTreeModel), wddxTree (extending swing.JTree) and wddxTreeApplet (extending swing.JApplet). Some of those classes have private classes defined within them (eg wddxTree includes a definition for class mouseListener(awt.event.MouseAdapter) ). Is it OK to have more than one top level class in a jython file to be compiled, or do I have to split those top-level classes into wddxNode.py, wddxTreeModel.py, wddxTree.py and the existing wddxTreeApplet.py. Presumadly private classes are OK to be defined within a previous class ? What about if I want to use a natively written python class (i.e a class not extending any java class/interface), is that simply not possible (I don't want to at the moment, but seems like it could be annoying to have to extend a java class for every class you want to write) ? >If >jythonc doesn't say this you got something wrong, imports or classpath >problems maybe. It's good to remember that jythonc compilation is nothing >like ordinary java compilation so don't count on really basic errors >being flagged just because it compiles. Yes, jythonc for the wddxTreeApplet isn't saying that wddxTreeApplet is extending JApplet (or anything for that matter), so I'm thinking that what I've said above is where the problem lies. >Be aware that you can specify more than one jar file in your applet >tag. >Like this: archive="jarnumberone.jar , jarnumbertwo.jar" Yep, got that :-) >This way you don't have to put all the files into the same jar. Alas I >have heard that this doesn't work with all browsers. It works on IE >6.0 which is what I have tested with. I believe it's a problem with NS up to 4.x, I don't care about NS up to 4.x (mozilla rules the world muharharhar) so it's not much of an issue. Thanks for your help --- James Sleeman |
From: Samuele P. <ped...@bl...> - 2002-02-05 03:09:02
|
> >Your .py file must have the same name as > >your class, and watch out for the message from jythonc that your > >python class is extending the java class, JApplet in your case. > > > Ok, I think this is where I am going wrong. The file i want to compile, wddxTreeApplet.py has four top level classes in it - wddxNode > (which extends swing.tree.DefaultMutableTreeNode), wddxTreeModel (extending swing.tree.DefaultTreeModel), wddxTree (extending > swing.JTree) and wddxTreeApplet (extending swing.JApplet). Some of those classes have private classes defined within them (eg > wddxTree includes a definition for class mouseListener(awt.event.MouseAdapter) ). > > Is it OK to have more than one top level class in a jython file to be compiled, or do I have to split those top-level classes into > wddxNode.py, wddxTreeModel.py, wddxTree.py and the existing wddxTreeApplet.py. Presumadly private classes are OK to be defined > within a previous class ? > What about if I want to use a natively written python class (i.e a class not extending any java class/interface), is that simply not possible > (I don't want to at the moment, but seems like it could be annoying to have to extend a java class for every class you want to write) ? > No you can have as many top-level classes as you like, both extending java classes or not. The class with the same name as the file will correspond to the class produced by jythonc (btw the other classes extending java will correspond to inner classes of the main java one (not that much important), the purely python classes have no such correspondence at all). For the rest you should consider that jythonc does a static analysis in order to understand which classes extend java classes, something plain as from javax.swing import JApplet class MyApplet(JApplet): ... import javax.swing class MyApplet(javax.swing.JApplet): ... should work. regards, Samuele Pedroni. |