gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 23:36:04 26 4
gpt4 key购买 nike

官方文档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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com