I'm trying to create a triangle that would be display along side rectangles and circles after I run NervousShapes. I can't seem to get it right. I try doing it with the math but doesn't create the triangle the way I want it. If anyone one has done the NervousShapes program and knows how to create a triangle please help (even if you have not). I know I'm missing something but don't quite get it.
It is this class that's the problem the other class that I have work just fine.
import java.awt.*;
public class Triangle extends Shape {
// Instance variables
private int diameter;
private static final int N_POINTS = 3;
private static int[] x = new int[3];
private static int[] y = new int[3];
// Constructor
public Triangle(int x, int y, Color color, int diameter) {
super(x, y, color);
this.diameter = diameter;
}
// Instance methods
public void draw(Graphics g) {
g.setColor(getColor());
// int[] x = {(getX()/3), getX(), (getX() + (getX()/3))};
// int[] y = {(getY()+getY()), getY(), (getY()+getY())};
g.fillPolygon(x, y, N_POINTS);
g.drawPolygon(x, y, N_POINTS);
}
public int getHeight() {
return diameter;
}
public int getWidth() {
return diameter;
}
private static int getNpoints()
{
return N_POINTS;
}
}