官方文档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 结构。 Graphics
和 Graphics2D
类是抽象的;具体实现取决于操作系统,并且故意不在 API 中公开。
关于java - Container 类中 Paint(Graphics g) 方法中 Graphics g 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18676811/