You need to look which methods are specific to the Graphics2D class. I think what is passed is an instance of a subclass of Graphics2D, but it is declared as Graphics. Graphics and Graphics2D are abstract classes, subclasses of each other. You might do well to use the create() method to create a copy of the object if you do anything complicated, eg shear().
nope. all i get is a warning from one class about using unchecked or unsafe operations. i first wrote it in 2004. it compiles and runs for me using java7.
Joined: Aug 05, 2005
Randall Twede wrote:as you figured out there are other classes
i didn't have any problems with missing classes - it was just a missing . on line 32 between this and color. If you copy and pasted this code into the post above, then this is not the code you are compiling.
Randall Twede wrote:i could maybe say public void draw(Graphics2D g)
instead of casting.
You would still have to cast in order to call your method from a Swing painting method e.g.Anywhere you need to treat a more general type -- a superclass -- as a more specific type -- a subclass -- you can't avoid casting (someone correct me if that's wrong).