简体   繁体   English

Java:图形还是 Graphics2D?

[英]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.我是 Java 的新手,并且一直在尝试在其中制作一些简单的游戏,并在屏幕上显示大量图像。 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..从那以后,我一直在使用“图形”class 来绘制这些图像、字符串和形状,但我最近遇到了 Graphics2D,这似乎是同一类东西。

Could anyone tell me what the difference is between them and which one would be the best to use?谁能告诉我它们之间有什么区别以及哪个最好用? Would I have to perform some large updates for my code if I wanted to use Graphics2D?如果我想使用 Graphics2D,我是否必须对我的代码进行一些大的更新?

The Graphics that is passed to paint(Graphics) is actually a Graphics2D object.传递给paint(Graphics)的Graphics实际上是一个Graphics2D object。 If you want to use any of the Graphics2D functionality, just cast it and make the calls you need.如果您想使用任何 Graphics2D 功能,只需转换它并进行所需的调用。

Graphics2D is newer and plugs into the newer Java 2D api set. Graphics2D 更新并插入更新的Java 2D api集。 Use Graphics2D unless you have to be backwards compatible.除非您必须向后兼容,否则请使用 Graphics2D。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM