1,105,592 Community Members

How to draw a rectangle in jython

Member Avatar
siga
Newbie Poster
5 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, I am given this assignment that should be run in Jython. The assignment says that the program consists of a Java application with a canvas and a textarea for turtle code. I need to create a Jython application that takes turtle code from the Java application, parses it with regular expressions and calls setPixel(x,y)
in the Java application to draw a rectangle. the Java program ,setPixel(x, y) is used to control the painting and getCode() to get the code entered in to the turtle code textarea. These methods are both defined in the DYPL Java class.

import Translater

class Jtrans(Translater):

    def __init__(self):
        pass

    def actionPerformed(self, event):
        print("Button clicked. Got event:")
        self.obj.setPixel(100,10)
        self.obj.setPixel(101,10)
        self.obj.setPixel(102,10)

    def move(self, x,y):
        move(50, 90) 
        move(100, 90)
        move(50, 90)
        move(100, 90)

    def put(self, x,y,a):
        put(150, 150, 0)
        for x in range(0,4): 
            move(50, 90)
        end


        eval("self."+self.obj.getCode()+"()")#why do we need this?

    def setDYPL( self, obj ):
        print("Got a DYPL instance: ")
        print(obj)

if __name__ == '__main__':
    import DYPL
    DYPL(Jtrans())

I also attach a zip file containing classes like Translater.class,DYPLCanvas.java etc if you need it. so does anyone know how I should start?

Member Avatar
pyTony
pyMod
6,104 posts since Apr 2010
Reputation Points: 818 [?]
Q&As Helped to Solve: 1,056 [?]
Skill Endorsements: 42 [?]
Moderator
Featured
 
0
 

You are not using the parameters to methods of JTrans, but you are using magic constants instead. You can not use module as function like you are trying in line 35.

Member Avatar
siga
Newbie Poster
5 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

It is provided by my lecturer to create the canvas to draw on. When I run it , the cmd window does not give any error. and it also draw a line.

Member Avatar
siga
Newbie Poster
5 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

My assignment is to draw a face not a rectangle. the rectangle is just so that I can see an example of how the coding should be done because I am not used to programming using java application

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 
Member Avatar
siga
Newbie Poster
5 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

yes I wrote it there. but as you can see no one responded

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 
Member Avatar
siga
Newbie Poster
5 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you for the reply. The link above shows how an object use the method created in turtle classs. My assignment requires me to create my own Turtle class.

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
0
 

Hint ...
Your turtle class will use the Jython canvas, just like the Python module turtle uses the Tkinter canvas.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: