Test the Jython Canvas

Updated vegaseat 3 Tallied Votes 585 Views Share

Just a simple Jython code to test drawing on the canvas.

''' jy_canvas_draw101.py
a simple Jython test program
draw a string
draw a rectangle
draw lines

download file jython_installer-2.5.2.jar
from http://www.jython.org/downloads.html

on Windows just double click the .jar file
and Java will install the Jython program
into a directory called jython2.5.2

to run on Windows use ...
C:/jython2.5.2/Jython.bat jy_canvas_draw101.py

result see: http://prntscr.com/shncp

info ...
http://docs.oracle.com/javase/tutorial/2d/basic2d/index.html

tested with jython2.5.2  by  vegaseat  12feb2013
'''

from java.applet import Applet
from java import awt

class MyCanvas(Applet):
    def paint(self, g):
        # draw a string at x=5 and y=10
        g.drawString("A Jython Canvas Rectangle", 5, 15)
        # draw a rectangle, ulc coordinates x=5, y=20
        w = 300
        h = 150
        g.draw3DRect(5, 20, w, h, 1)
        g.setColor(awt.Color.RED)
        d = 10
        g.draw3DRect(5+d, 20+d, w+d, h+d, 1)
        for x in range(50, 150, 10):
            for y in range(50, 100, 10):
                g.drawLine(x, y, x+d, y+d)


# test the module ...
if __name__ == '__main__':
    import pawt
    pawt.test(MyCanvas(), size=(400, 240))