FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


jython for web applets





MrTylerGreen
I have a working Python program. I have been dabbling in trying to get it to work as java applet within a browser, but I have had little success.

Basically I used this tutorial

http://stackoverflow.com/questions/1252965/distributing-my-python-scripts-as-jars-with-jython

to change omeglebot.py into omegle.jar

If I run:
Code:
java -jar omegle.jar

it works cross platform.

But If I try to run it as an applet I get this:

Code:
Java Plug-in 1.6.0_26
Using JRE version 1.6.0-oem-b104 Java HotSpot(TM) Client VM
User home directory = C:\Users\Jessica Graf
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


java.lang.reflect.InvocationTargetException
   at com.sun.deploy.util.DeployAWTUtil.invokeAndWait(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
   at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassCastException: Main cannot be cast to java.applet.Applet
   at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
   at java.awt.event.InvocationEvent.dispatch(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)
Exception: java.lang.reflect.InvocationTargetException


This is the code from Main.class:


Code:
import java.io.FileInputStream;
import java.lang.System;
import java.util.Properties;
import org.python.core.Py;
import org.python.core.PyException;
import org.python.core.PyFile;
import org.python.core.PySystemState;
import org.python.util.JLineConsole;
import org.python.util.InteractiveConsole;
import org.python.util.InteractiveInterpreter;

public class Main {

    private static InteractiveConsole newInterpreter(boolean interactiveStdin) {
        if (!interactiveStdin) {
            return new InteractiveConsole();
        }

        String interpClass = PySystemState.registry.getProperty(
        "python.console", "");
        if (interpClass.length() > 0) {
            try {
                return (InteractiveConsole)Class.forName(
            interpClass).newInstance();
            } catch (Throwable t) {
                // fall through
            }
        }
        return new JLineConsole();
    }

    public static void main(String[] args) throws PyException {
        PySystemState.initialize(
            PySystemState.getBaseProperties(),
            new Properties(), args);

        PySystemState systemState = Py.getSystemState();
        // Decide if stdin is interactive
        boolean interactive = ((PyFile)Py.defaultSystemState.stdin).isatty();
        if (!interactive) {
            systemState.ps1 = systemState.ps2 = Py.EmptyString;
        }

        // Now create an interpreter
        InteractiveConsole interp = newInterpreter(interactive);
        systemState.__setattr__("_jy_interpreter", Py.java2py(interp));
        interp.exec("try:\n import omeglebot\n omeglebot.start_Witnessing()\nexcept SystemExit: pass");
    }
}



ANY suggestions as to how I can create a jython interpreter and execute my python code will be appreciated Smile
Peterssidan
Java Applets don't execute main methods. Instead you inherit from the Applet class and override some of the methods.
Related topics
Macromedia updates Web conferencing tools
web-based project manager
Do you use a CMS script?
Play IRC Via Web
PHP Book (Php and Mysql for Dynamic Web Sites)
Web Based Game
Web e-mail !
Comment avoir son espace web?
PROFESSIONAL WEB DESIGN TUTORIAL
Create Web pages without knowing HTML.
QUALITY WEB SITE HOSTING
web proxy
What Happens When You Visit the Web Site ?
What is DS Applets ? enjoy this
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.