# Simple Graphics

• 10-04-2010, 11:38 PM
Freakzoyd
Simple Graphics
Hello guys, I am learning how to make ovals, rectangles, and all of the simple applet stuff right now. But I have some problems to understand how the coordinates work while trying to use all those figures to make drawings like a pumpkin, train etc.(Which i have the code but don't understand them). So my question is how the coordinates work and how can I draw the figure (in paper o I have heard people said that they used photoshop) before I write the code so that i can know in which coordinate and weight, height to make the drawing look nice?
• 10-05-2010, 01:37 AM
Norm
Best way I think is to find or write a simple program and try out various things to see how they work. Read the API doc for the Graphics and Graphics2D classes to see how their methods work. Then change your simple program to try using what you have read about.

• 10-05-2010, 02:12 AM
Freakzoyd
Hello Norm, I have been reading and found out how to make polygons, right now i am making a house. Which I only have the ceiling, but i have another problem. I make a triangle, and a rectangle to make the ceiling, but the polygon i used to complete the ceiling made 2 tringles instead of 1. Here is the code(I leave some space on the top to make a sun and clouds later on):

Code:

```import java.awt.*; import java.applet.*; public class GUILab extends Applet{     public void paint(Graphics g){         House casa=new House(g);     } } class House{     public House(Graphics g){         Tri(g);         Tech(g);     }     public void Tri(Graphics g){         Polygon tri=new Polygon();         tri.addPoint(200, 250);         tri.addPoint(125, 400);         tri.addPoint(275, 400);         g.setColor(Color.blue);         g.fillPolygon(tri);     }     public void Tech(Graphics g){         Polygon tech=new Polygon();         tech.addPoint(200, 250);         tech.addPoint(275, 400);         tech.addPoint(450, 250);         tech.addPoint(450, 400);         g.setColor(Color.red);         g.fillPolygon(tech);     } }```
• 10-05-2010, 02:29 AM
Norm
How did you put together the points that you are trying to draw? You need to take a piece of paper and write down the points in the order you want them and then transpose them into your program.
• 10-05-2010, 02:31 AM
Freakzoyd
That's what I did, but idk why it does that, did u run it to saw the problem?
• 10-05-2010, 02:35 AM
Norm
Try redesigning/changing the polygon points to be the shape you want.
• 10-05-2010, 02:47 AM
Freakzoyd
Now it works thanks.
Code:

```import java.awt.*; import java.applet.*; public class GUILab extends Applet{     public void paint(Graphics g){         House casa=new House(g);     } } class House{     public House(Graphics g){         Tech(g);         Tri(g);     }     public void Tri(Graphics g){         Polygon tri=new Polygon();         tri.addPoint(200, 250);         tri.addPoint(125, 400);         tri.addPoint(275, 400);         g.setColor(Color.blue);         g.fillPolygon(tri);     }     public void Tech(Graphics g){         g.setColor(Color.red);         g.fillRect(200, 250, 250, 150);     } }```