开发者

Why the drawPolygon method in Graphics Class abstract and I can still use it

开发者 https://www.devze.com 2023-02-16 19:46 出处:网络
In Graphics Class, there is an abstract method defined as public abstract void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)

In Graphics Class, there is an abstract method defined as

public abstract void drawPolygon(int[] xPoints, int[] yPoints, int nPoints)

Why do I still be able to use the method directly in my开发者_如何学Python code?

EDIT: In the Official java documentation, the only Direct Known Subclasses of Graphics is Graphics2D, which doesn't implement the method, and doesn't have any Direct Known Subclasses.


Yes, you can still use it because you are not actually using the abstract class Graphics in your code. Your application will be using a concrete subclass of Graphics, which is passed to methods such as paintComponent(Graphics). This concrete subclass will have drawPolygon(int[], int[], int) implemented.

This lesson on painting in Swing may help provide more details on how these methods work. The article Painting in AWT and Swing will also be useful.

0

精彩评论

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