0
我想创建两个三角形,一个倒过来,另一个倒上。但是,该程序仅绘制第一个三角形。我究竟做错了什么?试图绘制2个三角形
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'?如果没有,那就有你的答案。 – weston
但我不会在任何地方调用油漆,它仍然绘制三角形。 – Hundo
'paint'由另一个知道该方法的类调用,因为它在'Applet'中声明。没有其他班级对你的方法有任何了解,这是全新的,所以没有人会这样称呼它。 – weston