java - Container 类中 Paint(Graphics g) 方法中 Graphics g 的值

标签 java swing awt

官方文档paint(Graphics g)方法说:

Paints the container. This forwards the paint to any lightweight components that are children of this container. If this method is reimplemented, super.paint(g) should be called so that lightweight components are properly rendered. If a child component is entirely clipped by the current clipping setting in g, paint() will not be forwarded to that child. g - the specified Graphics window

但是我没有找到 Graphic 的功能是什么?作为参数传递的对象。

谁能解释一下它的意义。

谢谢。

最佳答案

“Swing 程序应该重写 paintComponent() 而不是重写 paint()”,如 Painting in AWT and Swing: The Paint Methods 中所述。 。提供给 paintComponent()Graphics 实例,有时称为图形上下文,允许 Java 程序操作主机操作系统拥有的 GUI 结构。 GraphicsGraphics2D 类是抽象的;具体实现取决于操作系统,并且故意在 API 中公开。

关于java - Container 类中 Paint(Graphics g) 方法中 Graphics g 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18676811/

相关文章:

java - 如何获取Map中值的大小?

java - 为什么我在响应 JSON 请求时收到 500 错误?

java在另一个上绘制图像

java - Swing组件默认渐变背景

java - 将 JTextArea 添加到 TabbedPane

java - 为什么 `gradle`在每个子项目中都执行 `ant.replaceregexp`?

java.exe=jvm 和 javac.exe=编译器

java - 缩短 AWT 异常堆栈跟踪

java - 如何通过鼠标拖动绘制一个倒置的正方形?

java - 冗长的 MouseListener 实现值得开销吗?