Q: Subclassing java with JPython. How?

Henrik Wetterstrom henke at news.bahnhof.se
Wed May 24 00:39:53 CEST 2000


Hi,

I am evaluating the combination Java av JPython, and since
I am not that experienced in any of the two, I would like some
guidance.

I am using jpythonc to make a java .class file from a JPython
class. This JPython class inherit from a Java class.

I fail to understand how the subclassed JPython class should be used
from java.

When I look at the java file that jpythonc creates from the
JPython file, every method I would consider to use, have been
made private.


Now consider the following three source files:


--[ Vehicle.java ]-----------------------------

// Java class that will be subclassed by Car.py
public class Vehicle {

  public void printLicenseplate() {
      System.out.println("ABC123");
  }

}

--[ Car.py ]-----------------------------------
# JPython class that will subclass Java Vehicle
import java  
import Vehicle
class Car(Vehicle):
    def start():                               
        on=1

    def stop():
        on=0

    def printStatus():
        if x=0:
            print "The car is stopped"
        else:
            print "The car is running"

--[ VehicleTest.java ]------------------------
// A Java test class just to test the two classes above
import java.lang.*;
import Vehicle;
import Car;

public class VehicleTest {

   public static void main(String[] args) {
       System.out.println("Starting");
       Car c = new Car();

       // None of these calls to methods in the
       // Car object will be accepted.
       c.printLicenseplate();
       c.start();
       c.printStatus();
   }

}

---------------------------------------------


I have searched through lots of places for information
about how this should be done without finding a good
answer. Since the output from jpythonc must be useful
somehow, there must be an obvious answer, but I fail to
see it right now.

Any feedback is greatly appreciated.


Regards,
Henrik W.




More information about the Python-list mailing list