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;
	}
	
	
}
griswolf commented: Use the right forum. And the CODE button +0
ztini commented: Didn't deserve to be downrated -- this is the right forum. +1

Looks like you only have half the program. That's a class that implements a single triangle. Somewhere else there should be some code that maintains an array or ArrayList of these Triangles, and creates the GUI element(s) in which the Triangles are to be drawn.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.