Java: Graphics or Graphics2D?
I am new to Java and have been trying to make some simple games in it with lots of images on screen. Since then I have been using the 'Graphics' class to draw these images, strings and shapes, but I recently came across Graphics2D which seems to be the same sort of thing..
Could anyone tell me what the difference is between them and which one would be the best to use开发者_JAVA百科? Would I have to perform some large updates for my code if I wanted to use Graphics2D?
The Graphics that is passed to paint(Graphics) is actually a Graphics2D object. If you want to use any of the Graphics2D functionality, just cast it and make the calls you need.
Graphics2D is newer and plugs into the newer Java 2D api set. Use Graphics2D unless you have to be backwards compatible.
精彩评论