From: <rem...@fr...> - 2003-04-30 15:47:08
|
Greetings, I'm having troubles with type coercion / casting with java.awt.Graphics objects: I want to use the drawPolygon() method but at runtime JPanel.getGraphics() returns a sun.awt.windows.WGraphics and the Jython interpreter try to cast it into a sun.java2d.SunGraphics2D. I never had such problems with Java. I don't know what to do. Moving back to Java programming ? Jython is just so GREAT ! I can't go back to Java !!! Remy Moueza class JDisplay ( JPanel, MouseListener, MouseMotionListener ): ... def display_poly ( self, poly, screen ): ... x_values = [] y_values = [] for point in poly.points : x, y = screen.output ( point ) x_values.append ( x ) y_values.append ( y ) gc = self.getGraphics () print gc x_coord = array ( x_values, "i" ) y_coord = array ( y_values, "i" ) gc.drawPolygon ( x_coord, len( x_values ), y_coord, len( y_values )) Here is the error message : sun.awt.windows.WGraphics # -> print gc Traceback (innermost last): File "C:\lecteurD\monDev\3Dmoteur\python\JAffichage.py", line 0, in main File "C:\lecteurD\monDev\3Dmoteur\python\JAffichage.py", line 0, in display File "C:\lecteurD\monDev\3Dmoteur\python\JAffichage.py", line 0, in display_facette TypeError: drawPolygon(): 1st arg can't be coerced to sun.java2d.SunGraphics2D |