Hello,
I'm using Java and Python together with Jython and I'm having trouble with some python syntax. I have a custom listener that I want to add to an object. Usually I'd do it like this:
class ballCollisionListener(animation.CollisionListener):
def collisionDetected(self,event):
if event.getSource()==boundary:
if ball.getX()<=0 or ball.getX()+ball.getWidth()>=boundary.getWidth():
ball.setXSpeed(-ball.getXSpeed())
elif ball.getY()<=0 or ball.getY()+ball.getHeight()>=boundary.getHeight():
ball.setYSpeed(-ball.getYSpeed())
elif event.getSource()==paddle:
ball.setYSpeed(-ball.getYSpeed())
ball.addCollisionListener(ballCollisionListener())
but I think I shouldn't have to create a new class everytime.
In java if I wanted to do this it would be something like:
ball.addCollisionListener(new CollisionListener()
{
}