From: Zhong Wenstone-a. <a1...@mo...> - 2004-06-07 08:38:48
|
Hi, Scratching Frame,Panels to test a java2d code snippet is always boring. I use a little toolkit wrote in Jython to help on this, Get visual feedback immediately. To use it: Jython 2.1 on java1.4.1_02 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> from prac2d import * >>> start() >>> g2d.drawString("Test",0,0) >>> g2d.drawString("Test",10,10) >>> #----------------------file: prac2d.py----------------------------# import java import javax from javax.swing import * from java.awt import * from java.awt.geom import * from java.awt.event import * from java.awt.image import * from java.lang import * import thread import time jf_width = 400 jf_height = 400 bi = BufferedImage(jf_width,jf_height,BufferedImage.TYPE_INT_RGB) class WindowClosingListener(WindowAdapter): def windowClosing(self,evt): java.lang.System.exit(0) class Panel(javax.swing.JPanel): def paint(self,g): global bi if bi != None: g.drawImage(bi,0,0,None) class MyFrame(javax.swing.JFrame): def __init__(self,title): javax.swing.JFrame.__init__(self,title) self.addWindowListener(WindowClosingListener()) self.setSize(jf_width,jf_height) def addComp(self,jCom): self.getContentPane().add(jCom) jf = MyFrame("Prac 2d") jp = Panel() jf.addComp(jp) g2d = bi.createGraphics() def update(): while 1: time.sleep(0.05) jf.repaint() def start(): jf.show() thread.start_new_thread(update,()) #-----------------------------------------------------------------# |