I am having problems. I am trying to run a program that output suppose to be mutiple triangles but when I run it. I only get one. Here is the code please tell me what I am doing wrong.
Thank you Kevin!
import java.awt.Color;
import java.awt.Graphics;
public class Triangle extends Shape {
private int width;
private int height;
@Override
public void draw(Graphics g){
// set the color to receiver instance's color
g.setColor(color);
// draw a triangle at receiver instance's position
int[] x = {200,50,250};
int[] y = {200,200,250};
g.fillPolygon(x,y,3);
}
public int getSize(){return size;}
public int[] getPosition(){ return position;}
public Color getColor(){return color;}
/**
* The only abstract method so all descendants must
* have their own version of draw
* @param g
*/
//get height
public int getheight(){
return height;
}
//get width
public int getwidth(){
return width;
}
public String toString(){
String s = super.toString();
s +="\nHeight:" + height;
s +="\nWidth:" + width;
return s;
}
public void setwidth(int w){
if (w < 0)
width = 1;
else
width = w;
}
public void setheight(int h){
if (h < 0)
height = 1;
else
height = h;
}
}