ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> Jython-dev
Jython-dev
[Jython-dev] Coercion or cast trouble with Jython and Swing...
by other posts by this author
Apr 30 2003 3:43PM messages near this date
[Jython-dev] Jython Console with Code Completion | Re: [Jython-dev] Coercion or cast trouble with Jython and Swing...
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



-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore.
Now part of Progress Software. http://www.objectstore.net/sourceforge
_______________________________________________
Jython-dev mailing list
Jython-dev@[...].net
https://lists.sourceforge.net/lists/listinfo/jython-dev
Thread:

Oti

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved