Trouble with Shapes!

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.

So what are you having trouble with exactly?

Getting the triangle drawn? Getting a triangle?

i’m having trouble drawing the triangle

So have you created your JPanel to draw on yet?

Here are some links to look at and follow:

http://leepoint.net/notes-java/GUI-lowlevel/graphics/40drawingpanel/10drawingpanel.html

Hope that helps you out.