本文介绍了为什么Graphics Class abstract中的drawPolygon方法我还能用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Graphics Class,有一个抽象方法定义为

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

为什么我仍然可以直接在我的代码中使用该方法?

在Java官方文档中,Graphics唯一的Direct known SubclassesGraphics2D,它没有实现方法,也没有任何直接已知子类.

解决方案

是的,您仍然可以使用它,因为您实际上并没有在代码中使用抽象类 Graphics.您的应用程序将使用 Graphics 的具体子类,该子类被传递给诸如 paintComponent(Graphics) 之类的方法.这个具体的子类将实现 drawPolygon(int[], int[], int).

这个关于在 Swing 中绘画的课程可能有助于提供更多有关这些方法如何工作的详细信息.文章在 AWT 和 Swing 中绘画 也很有用.>

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 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.

这篇关于为什么Graphics Class abstract中的drawPolygon方法我还能用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 00:54