【发布时间】:2017-06-29 10:48:05
【问题描述】:
我正在尝试创建两个三角形,其中一个倒置并在另一个之上。但是,该程序仅绘制第一个三角形。我做错了什么?
public class Triangle extends Applet {
public void paint( Graphics g ) {
int[] xPoints = {10, 260, 135};
int[] yPoints = {250, 250, 10};
int numPoints = 3;
// Set the drawing color to black
g.setColor(Color.black);
// Draw a filled in triangle
g.fillPolygon(xPoints, yPoints, numPoints );
}
public void newTriangle( Graphics h ) {
int[] xPoints2 = {135, 395/2, 145/2};
int[] yPoints2 = {250, 130, 130};
int n = 3;
h.setColor(Color.white);
h.fillPolygon(xPoints2, yPoints2, n);
}
}
【问题讨论】:
-
你在哪里打电话给
newTriangle?如果没有,这就是你的答案。 -
但是我也没有在任何地方调用paint,它仍然绘制三角形。
-
paint被另一个知道该方法的类调用,因为它在Applet中声明。没有其他班级对您的方法有任何了解,它是全新的,所以没有人调用它。 -
那么我如何在同一个类中调用它?
-
看我的回答
标签: java applet awt graphics2d