0
2つの三角形を上下逆さに作成しようとしています。しかし、プログラムは最初の三角形だけを描いています。私は間違って何をしていますか?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