开发者

Passing an abstract Graphics object to paintComponent()

开发者 https://www.devze.com 2023-02-19 23:20 出处:网络
In Java, when using the paintComponent() method for a JPanel, the parameter that is passed is an object from the abstract class Graphics. Since using an abstract object doesn\'t make sense, I\'m assum

In Java, when using the paintComponent() method for a JPanel, the parameter that is passed is an object from the abstract class Graphics. Since using an abstract object doesn't make sense, I'm assuming the object that is actually passed is from a concrete subclass of Graphics.

My question is, what 开发者_JAVA技巧is this concrete subclass of Graphics, and where was it generated?

public void paintComponent(Graphics g) { ... }


It should be

sun.java2d.SunGraphics2D which is extended from java.awt.Graphics2D

each top level Component should have a reference to one, and any child components ask their parent for one until the parent can satisfy the request.

0

精彩评论

暂无评论...
验证码 换一张
取 消