public class Triangle extends Polygon implements Drawable { Color triangleColor; Polygon triangleShape; int currentX; int currentY; public Triangle() { Triangle t = makeDefaultTriangle(); setColor(t.getColor()); setShape(t.getShape()); setPosition(t.getX(),t.getY()); } public Triangle(Color c,Polygon p,int x,int y) { setColor(c); setShape(p); setPosition(x,y); } public void setColor(Color c) { triangleColor = c; } public Color getColor() { return triangleColor; } public void setShape(Polygon p) { triangleShape = new Polygon(p.xpoints,p.ypoints,p.npoints); } public Polygon getShape() { return triangleShape; } public void setX(int x) { currentX = x; } public int getX() { return currentX; } public void setY(int y) { currentY = y; } public int getY() { return currentY; } public void setPosition(int x,int y) { setX(x); setY(y); } public void paint(Graphics g) { Color c = getColor(); Polygon p = getShape(); int[] x = (int[]) p.xpoints.clone(); int[] y = (int[]) p.ypoints.clone(); int n = p.npoints; for(int i = 0;i < n; i++) { x[i] += getX(); y[i] += getY(); } p = new Polygon(x,y,n); g.setColor(c); g.fillPolygon(p); } public static Triangle makeDefaultTriangle() { int[] x = {0,3,0}; int[] y = {0,0,4}; Color c = Color.WHITE; Polygon p = new Polygon(x,y,x.length); return new Triangle(c,p,0,0); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)