I’m trying to code a triangle in Java and am having difficulty.
Here’s my code. I know it’s probably simple but I hope someone can help.
import java.awt.Graphics;
public class Triangle {
int x=50, y=50;
int size=20;
public void moveTo(int xpos, int ypos){
x=xpos; y=ypos;
}
public void draw(Graphics g){
g.drawLine(x, y, x+size, y);
g.drawLine(x+size, y, x+size/2, y+size);
g.drawLine(x+size/2, y+size, x, y);
}
}
If you could help me do this then I would really appreciate it.
Also I need so pass an array of different values for the triangle through aswell.
Thanks for the help.