Results 1 to 7 of 7

Thread: Simple Graphics

  1. #1
    Freakzoyd is offline Member
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Default 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?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    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.

    If you have questions about your code, post the code and your questions.

  3. #3
    Freakzoyd is offline Member
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Default

    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):

    Java 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);
        }
    }

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    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.

  5. #5
    Freakzoyd is offline Member
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Default

    That's what I did, but idk why it does that, did u run it to saw the problem?

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default

    Try redesigning/changing the polygon points to be the shape you want.

  7. #7
    Freakzoyd is offline Member
    Join Date
    Jul 2010
    Posts
    27
    Rep Power
    0

    Default

    Now it works thanks.
    Java 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);
        }
    }

Similar Threads

  1. How to use graphics
    By Mattedatten in forum New To Java
    Replies: 3
    Last Post: 03-18-2010, 03:10 PM
  2. New simple application using a simple database
    By webbusiness23 in forum New To Java
    Replies: 9
    Last Post: 08-03-2009, 03:55 AM
  3. Replies: 2
    Last Post: 05-04-2008, 06:27 PM
  4. graphics
    By Joe2003 in forum Advanced Java
    Replies: 4
    Last Post: 01-18-2008, 08:44 PM
  5. Graphics
    By feniger in forum New To Java
    Replies: 1
    Last Post: 12-29-2007, 05:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •