JPython, getting started Q.

Alex Rice alrice at swcp.com
Sat Oct 9 19:46:33 EDT 1999


Hi, I'm *really* interested in JPython, but I am having trouble getting started
with some simple applets. I'm sure I just don't understand how JPython calls
java overloaded methods...

Consider the following Java code, to initialize a Java applet and get the
graphics
context for double-buffered rendering:

import java.applet.*;
import java.awt.*;

public class Render extends Applet implements Runnable  {

    Image image;
    Graphics graphics;
    Thread thread;
  
    public void init() {
	super.init();
	image = createImage(getBounds().width, getBounds().height);
	graphics = image.getGraphics();
	requestFocus();
    }
    <snip>

Now, trying to implement this in JPython, I can't get past the createImage()
call.
I never get an image returned, it's always None.

from java.applet import *
from java.awt import *

class MyApplet(Applet):

    def init(self):
        Applet.init(self)
        self.image = self.createImage(640,480)
        self.graphics = self.image.getGraphics()
        self.requestFocus()
    <snip>

Here is some interactive which kinds of illustrates what the problem is:

JPython 1.1beta3 on java1.1.7B (JIT: null)
Copyright (C) 1997-1999 Corporation for National Research Initiatives
>>> from java.applet import *
>>> from java.awt import *
>>> o = Applet()
>>> o
java.applet.Applet[panel0,0,0,0x0,invalid,layout=java.awt.FlowLayout]
>>> o.createImage
<method java.awt.Component.createImage of java.applet.Applet instance at
135125757>
>>> o.createImage(100,100)
>>> o.createImage(None)
sun.awt.motif.X11Image at 80dd548
>>> 

The former should call java.awt.Component.createImage(int width, int height)
the latter calls java.awt.Component.createImage(ImageProducer producer)

I can't get the former (what I want) to work! Any suggestions? Thanks!

Also, is there any equivalent to java's "implements" in Jpython? If I understand
correctly, that's only used by the Java compiler to enforce interfaces, right?

Alex Rice




More information about the Python-list mailing list