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.
精彩评论